129

I'm trying to use robocopy to transfer a single file from one location to another but robocopy seems to think I'm always specifying a folder. Here is an example:

robocopy "c:\transfer_this.txt" "z:\transferred.txt"

But I get this error instead:

2009/08/11 15:21:57 ERROR 123 (0x0000007B) Accessing Source Directory c:\transfer_this.txt\

(note the \ at the end of transfer_this.txt)

But if I treat it like an entire folder:

robocopy "c:\folder" "z:\folder"

It works but then I have to transfer everything in the folder.

How can I only transfer a single file with robocopy?

Kevin Panko
  • 161
  • 13
  • ```def copyFile(fromLocation,toLocation,big=False): print("copy file from " + fromLocation + " to " + toLocation) if big: iFind=fromLocation.rfind('\\') fromLocation1 = fromLocation[: (iFind+1)] fileName=fromLocation[iFind+1 :] toLocation1 = toLocation[:(toLocation.rfind('\\')+1)] strcmd="robocopy "+fromLocation1+" "+toLocation1+" "+fileName print(strcmd) os.system(strcmd) else: shutil.copy2(fromLocation,toLocation)``` – Gank May 24 '17 at 09:33

4 Answers4

170

See: Robocopy /?

Usage : ROBOCOPY source destination [file [file]...] [options]

robocopy c:\folder d:\folder transfer_this.txt
Desperatuss0ccus
  • 252
  • 1
  • 4
  • 9
KPWINC
  • 11,274
  • 3
  • 36
  • 44
  • fwiw, at least on win2003: Quoting directory paths seems to make it hiccup. – Jonesome Reinstate Monica Sep 15 '13 at 19:52
  • 2
    @samsmith I've seen it hiccup when you have a \ before the closing quote (i.e.: ROBOCOPY "c:\folder1\" c:\folder2 file won't work but: ROBOCOPY "c:\folder1" c:\folder2 file does. I expect it's a text escaping thing – Mike Goatly Oct 23 '15 at 07:22
  • 3
    @MikeGoatly Excellent point. Robocopy does NOT like trailing \. It wants you to name the directories as "names" and does not want to imply in any way that it accepts anything other than a directory. – Jonesome Reinstate Monica Oct 23 '15 at 16:26
  • Generally you leave the trailing "\" off, but you can add a trailing space after the final "\" like: `robocopy "c:\folder\ " "f:\folder" ... ` or `robocopy "c:\ " "f:\folder" ... `, the escaped trailing space will be ignored although it's rather counter intuitive so I don't use it but it is one way to specify copying from the root. Another is to log to the desired folder then just specify the drive letter like: `cd "c:\"` -> `robocopy "c:" "f:\folder" ... `. And this also works to specify the root as the source: `robocopy "c:\Temp\.." "f:\folder" ... ` – Kevin Fegan Sep 19 '21 at 11:42
  • if this is between two drives you can use the current directory of each drive. `cd` to `c:\folder`, switch to `d:` and `cd` to `d:\folder`, and then use `robocopy c: d: transfer_this.txt` – Dave Cousineau Dec 09 '21 at 18:59
22

According to the Wikipedia article on Robocopy:

Folder copier, not file copier

Robocopy syntax is markedly different from standard copy commands, as it accepts only folder names as its source and destination arguments. File names and wild-card characters (such as *.*) are not valid source or destination arguments. Files may be selected or excluded using the optional filespec filtering argument. Filespecs can only refer to the filenames relative to the folders already selected for copying. Fully-qualified path names are not supported.

For example, in order to copy the file foo.txt from directory c:\bar to c:\baz, one could use the following syntax:

robocopy c:\bar c:\baz foo.txt

Kevin Panko
  • 161
  • 13
Adrian De Leon
  • 321
  • 2
  • 2
  • 2
    One thing I noticed. If C:\bar has any folders in it and the option /e has been added. It will recreate all the folders with no files in them. I guess since the foo.txt acts like a filter and couldn't find any files in those folders and your keeping empty folders. Thats why the empty folders are created. – Donny V Aug 02 '17 at 20:02
2

Try inserting a space before the destination, like this:

robocopy "c:\transfer_this.txt" "z: \this.txt" 

notice the space after the destination "folder" z:.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
user296831
  • 29
  • 1
  • 3
    This did not work for me, I had to follow @KPWINC's instructions and leave the file name out of the source path. – influent Nov 25 '15 at 00:17
  • 5
    This is a troll answer? Tried and does not work (nor does it seem like it would have worked). – Pacerier May 04 '16 at 04:24
-4

robocopy Q:\ F:\Dopbox "Microsoft Office.zip" /MT:128

Dale
  • 9