4

We are in the process of migrating files from one share to another. We have built a tool in which the user can select directories and/or individual files to be copied to a destination share. The tool generates an individual RoboCopy command for each of the files or directories in the collection that results from the selection made by the user.

We are having problems if an individual file to be copied starts with a dash, for instance:

robocopy c:\temp c:\temp2 -a.txt

RoboCopy bails out with: ERROR : Invalid Parameter #3 : "-a.txt" We tried the usual suspects (quotes around the filename etc.), but so far nothing seems to work. Any idea how to get around this, without resorting to renaming the file prior to copying?

1 Answers1

3

This appears to be a bug in robocopy; it has some other known similar ones:

https://support.microsoft.com/en-us/kb/2646454

Here's a possible workaround:

robocopy c:\temp c:\temp2 *-a.txt /xf *?-a.txt

*-a.txt will still match "-a.txt", but it also matches "x-a.txt", "xx-a.txt", etc.

The /xf file exclusion knocks out "x-a.txt", "xx-a.txt", and any other file with characters (specifically, at least one character) in front of the hyphen.

I've confirmed that the above command will match only "-a.txt" even if c:\temp also contains these files:

other folder\-a.txt
-a.txt1
-a1.txt
x-a.txt
xx-a.txt

I'm not 100% confident though, so you might want to think up some other filenames to test that against.

Felix
  • 433
  • 4
  • 8