因此,虽然似乎命令行参数是 v v v......argument delimiters v.........v v..........v ......quoted blocksxcopy "x:\souce\" "x:\target\" ^.......^ ^........^ ......argument data arg #1 arg #2 arg #1 = x:\source\ arg #2 = x:\target\ xcopy处理的实际参数是 v v .....argument delimiters v......................v .....quoted blockxcopy "x:\souce\" "x:\target\" ^.....................^ .....argument data arg #1 arg #1 = x:\source" x:\target"当删除结尾的反斜杠或包含其他点时,参数中的结束引号将不被转义,它将关闭引号中的块,并且参数之间的空格将被视为定界符.Hi I have this little command to copy files in a batch, which will help because I do this specific copy multiple times a day. The problem occurs while using the xcopy command. Everything is in order, but I am receiving this error: "Invalid path 0 files copied". Here is the code:C:\Windows\System32\xcopy /Y "C:\Users\Ryan\Desktop\mmars_pub\" "C:\Users\Ryan\Desktop\Dropbox\MMARS\mmars_pub\"I'm using the full path to the xcopy executable because I was having trouble configuring the path environment variable to function properly. I would imagine that it shouldn't affect the result though. I read somewhere about the "Prevent MS-DOS-based programs from detecting Windows" checkbox that should fix the issue, but I just can't seem to find that. Any help appreciated. 解决方案 Original answerRemove the ending backslash from the source folder pathC:\Windows\System32\xcopy.exe /Y "C:\Users\Ryan\Desktop\mmars_pub" "C:\Users\Ryan\Desktop\Dropbox\MMARS\mmars_pub\"edited 2015/10/01While the original question used a literal path, and the indicated solution will solve the problem, there is another option. For literal paths and in cases where the path is inside a variable and could (or not) end in a backslash, it is enough to ensure that the ending backslash (if present) is separated from the quote, including an ending dot. xcopy /y "x:\source\." "x:\target"xcopy /y "%myVariable%." "x:\target"This ending dot will not interfere in files/folders names. If there is and ending backslash, the additional dot will simply refer to the same folder. If there is not ending backslash as in windows files and folders can not end their names with a dot, it will be discarded.BUT if the output of the xcopy command will be processed, remember that this additional dot will be included in the paths shown.note: The solutions are above the line. Keep reading if interested on why/where there is a problem.Why xcopy "c:\source\" "d:\target\" fails but xcopy "c:\source" "d:\target\" works?Both commands seems to have valid path references, and ... YES! both are valid path references, but there are two elements that work together to make the command fail:the folder reference is quoted (note: it should be quoted, is a good habit to quote paths as you never know when they will contain spaces or special characters)xcopy is not an internal command handled by cmd but an executable fileAs xcopy is an external command, its arguments are not handled following the cmd parser command line logic. They are handled by the Microsoft C startup code.This parser follows two sets of rules, official rules and undocumented/non official rules (How Command Line Parameters Are Parsed)This parser sees the sequence \" found at the end of the "first" argument as a escaped quote that does not end/closes the argument, it is seen as part or the argument. And the "starting" quote of the "second" argument is just ending the double quoted block BUT not ending the argument, remember that arguments are delimited by white space.So while it seems that the command line arguments are v v v......argument delimiters v.........v v..........v ......quoted blocksxcopy "x:\souce\" "x:\target\" ^.......^ ^........^ ......argument data arg #1 arg #2 arg #1 = x:\source\ arg #2 = x:\target\the actual argument handled by xcopy is v v .....argument delimiters v......................v .....quoted blockxcopy "x:\souce\" "x:\target\" ^.....................^ .....argument data arg #1 arg #1 = x:\source" x:\target"When the ending backslash is removed or the additional dot included, the closing quote in the argument will not be escaped, it will close the quoted block and the space between arguments will be seen as a delimiter. 这篇关于“复制了无效的路径0文件";使用xcopy命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 01:23