“复制的路径 0 文件无效"使用 xcopy 命令时出错 [英] "invalid path 0 files copied" Error while using xcopy command

查看:55
本文介绍了“复制的路径 0 文件无效"使用 xcopy 命令时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小命令可以批量复制文件,这会有所帮助,因为我每天多次执行此特定复制.使用 xcopy 命令时会出现此问题.一切正常,但我收到此错误:复制的路径 0 文件无效".代码如下:

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:WindowsSystem32xcopy  /Y "C:UsersRyanDesktopmmars_pub" "C:UsersRyanDesktopDropboxMMARSmmars_pub"

我正在使用 xcopy 可执行文件的完整路径,因为我在配置路径环境变量以使其正常运行时遇到问题.我认为它不应该影响结果.我在某处阅读了有关防止基于 MS-DOS 的程序检测 Windows"复选框的内容,该复选框应该可以解决该问题,但我似乎无法找到它.任何帮助表示赞赏.

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.

推荐答案

原答案

从源文件夹路径中删除结尾的反斜杠

Remove the ending backslash from the source folder path

C:WindowsSystem32xcopy.exe  /Y "C:UsersRyanDesktopmmars_pub" "C:UsersRyanDesktopDropboxMMARSmmars_pub"


编辑 2015/10/01


edited 2015/10/01

虽然原始问题使用了文字路径,并且指示的解决方案将解决问题,但还有另一种选择.对于文字路径以及路径在变量内并且可以(或不)以反斜杠结尾的情况,足以确保结尾反斜杠(如果存在)与引号分开,包括结尾点.

While 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:	arget"
xcopy /y "%myVariable%." "x:	arget"

此结尾点不会干扰文件/文件夹名称.如果有并以反斜杠结尾,附加的点将仅指同一个文件夹.如果没有结尾反斜杠,如 windows 文件和文件夹不能以点结尾,它将被丢弃.

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.

但是如果 xcopy 命令的输出将被处理,请记住这个额外的点将包含在显示的路径中.

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.

为什么 xcopy c:source"d: arget" 失败,但 xcopy c:source"d: arget" 有效吗?

Why xcopy "c:source" "d: arget" fails but xcopy "c:source" "d: arget" 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:

  • 文件夹引用被引用(注意:它应该被引用,引用路径是一个好习惯,因为你永远不知道它们什么时候会包含空格或特殊字符)
  • xcopy 不是由 cmd 处理的内部命令,而是一个可执行文件
  • the folder reference is quoted (note: it should be quoted, it 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 file

由于 xcopy 是一个外部命令,它的参数不会按照 cmd 解析器命令行逻辑处理.它们由 Microsoft C 启动代码处理.

As 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

  • 参数由空格分隔,空格或制表符.

  • Arguments are delimited by white space, which is either a space or a tab.

被双引号包围的字符串被解释为单个参数,而不管其中包含的空格.一个引用字符串可以嵌入到参数中.请注意,插入符号 (^) 不是识别为转义字符或分隔符.

A string surrounded by double quotation marks is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument. Note that the caret (^) is not recognized as an escape character or delimiter.

以反斜杠开头的双引号 " 被解释为文字双引号 (").

A double quotation mark preceded by a backslash, ", is interpreted as a literal double quotation mark (").

反斜杠按字面解释,除非它们紧跟在双引号之前.

Backslashes are interpreted literally, unless they immediately precede a double quotation mark.

如果偶数个反斜杠后跟一个双引号,那么每个反斜杠()都会放在argv数组中一对反斜杠 (\) 和双引号 (") 是解释为字符串分隔符.

If an even number of backslashes is followed by a double quotation mark, then one backslash () is placed in the argv array for every pair of backslashes (\), and the double quotation mark (") is interpreted as a string delimiter.

如果奇数个反斜杠后跟一个双引号,那么每个反斜杠 () 都会被放置在 argv 数组中一对反斜杠 (\) 和双引号被解释作为剩余反斜杠的转义序列,导致文字要放在 argv 中的双引号 (").

If an odd number of backslashes is followed by a double quotation mark, then one backslash () is placed in the argv array for every pair of backslashes (\) and the double quotation mark is interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (") to be placed in argv.

和未记录/非官方规则(如何解析命令行参数)

and undocumented/non official rules (How Command Line Parameters Are Parsed)

  • 在双引号块之外," 开始一个双引号块.
  • 在双引号块内,一个 " 后跟一个不同的字符(不是另一个 ")结束双引号块.
  • 在双引号块中," 紧跟另一个"(即")导致单个" 要添加到输出中,并且双引号块继续.
  • Outside a double quoted block a " starts a double quoted block.
  • Inside a double quoted block a " followed by a different character (not another ") ends the double quoted block.
  • Inside a double quoted block a " followed immediately by another " (i.e. "") causes a single " to be added to the output, and the double quoted block continues.

此解析器将 first" 参数末尾的序列 视为不结束/关闭参数的转义引号,它被视为部分或论点.并且 second" 参数的 starting" 引号只是结束双引号块,但不会结束参数,请记住参数由空格分隔.

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.

所以虽然似乎命令行参数是

     v           v            v......argument delimiters
      v.........v v..........v ......quoted blocks
xcopy "x:souce" "x:	arget"
       ^.......^   ^........^  ......argument data
       arg #1      arg #2

       arg #1 = x:source
       arg #2 = x:	arget

xcopy 处理的实际参数是

     v                        v .....argument delimiters
      v......................v  .....quoted block
xcopy "x:souce" "x:	arget"
       ^.....................^  .....argument data
      arg #1    

      arg #1 = x:source" x:	arget"

当结束反斜杠被移除或包含额外的点时,参数中的结束引号将不会被转义,它将关闭被引用的块,并且参数之间的空格将被视为分隔符.

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 命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆