简体   繁体   English

robocopy将选项视为文件

[英]robocopy treats options as files

When i use robocopy to copy a file and use the option /IS to overwrite if already present at the destination. 当我使用robocopy复制文件并使用/IS选项覆盖时(如果已存在于目标位置)。 It treats the option as another file as can be seen by the logs: ERROR : Invalid Parameter #4 : "C:/Program Files/Git/IS" 它将选项视为另一个文件,如日志所示: ERROR : Invalid Parameter #4 : "C:/Program Files/Git/IS"

Anybody knows how to copy files in windows while overwriting the file at the destination. 任何人都知道在覆盖目标文件时如何在Windows中复制文件。

$ robocopy "Z:\ubuntushare" "C:\Natlink\Natlink\MacroSystem" "_git.py" /IS

   ROBOCOPY     ::     Robust File Copy for Windows

  Started : Sat Sep 17 18:00:05 2016

   Source - Z:\ubuntushare\
     Dest - C:\Natlink\Natlink\MacroSystem\

    Files : _git.py

  Options : /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : "C:/Program Files/Git/IS"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /?


****  /MIR can DELETE files as well as copy them !

pri@pri-PC MINGW64 /c/NatLink/NatLink/MacroSystem

edited 2016/09/19 - Tested and it works 2016/09/19 编辑 -经过测试,可以正常工作

From the MinGW Posix path conversion MinGW Posix路径转换

An argument starting with 2 or more / is considered an escaped Windows style switch and will be passed with the leading / removed and all \\ changed to /. 以2或更大的/开头的参数被认为是Windows样式的转义参数,将以前导/删除且所有\\更改为/传递。

  • Except that if there is a / following the leading block of /, the argument is considered to be a UNC path and the leading / is not removed. 除非在/的前导块后面有一个/,否则该参数被视为UNC路径,并且不删除前导/。

note : this is just a small extract of the full list. 注意 :这只是完整列表的一部分。 it is better to read the full list when working with the git bash shell in windows 最好在Windows中使用git bash shell时阅读完整列表

So, in this case, the solution is to double the forward slash in the switch 因此,在这种情况下,解决方案是将交换机中的正斜杠加倍

robocopy "Z:\ubuntushare" "C:\Natlink\Natlink\MacroSystem" "_git.py" //IS

ROBOCOPY uses the windows style forward slash / to specify command line options. ROBOCOPY使用Windows样式正斜杠/指定命令行选项。 That doesn't work well with Git-bash or similar terminals since the slash is interpreted as the root path in Linux and similar environments. 这在Git-bash或类似的终端上不能很好地工作,因为斜线被解释为Linux和类似环境中的root路径。

The shell is interpreting the /something as a file something under the root folder C:\\Program Files\\Git\\ and not a command line option. 外壳采用解释/something作为文件something在根目录下的文件夹C:\\Program Files\\Git\\而不是命令行选项。 So that ends up meaning "C:\\Program Files\\Git\\something" which doesn't exist. 这样最终就意味着"C:\\Program Files\\Git\\something"不存在。

Even trying to use the help option /? 甚至试图使用帮助选项/? fails with a similar error. 失败并显示类似错误。

Use the linux/unix/mac standard -opt instead of /opt . 使用linux / unix / mac standard -opt代替/opt Robocopy allows using dash/hyphen - to specify options. Robocopy允许使用破折号/连字符-指定选项。 eg robocopy -? 例如robocopy -? works and shows usage info/help. 可以显示使用信息/帮助。 So do: 这样:

robocopy "Z:\ubuntushare" "C:\Natlink\Natlink\MacroSystem" "_git.py" -IS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM