RoboCopy - Files starting with a dash result in error

删除回忆录丶 提交于 2019-12-02 04:23:50

问题


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:


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.



来源:https://stackoverflow.com/questions/30607819/robocopy-files-starting-with-a-dash-result-in-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!