windows 设置排除参数时,xcopy 返回错误“参数数量无效”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30651776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xcopy returns error "Invalid number of parameters" when exclude parameter is set
提问by user4157124
Issuing:
发行:
xcopy X:\ "Y:\...\bin76543210\" /c /g /d /i /e /r /h /y
works as expected. However:
按预期工作。然而:
xcopy X:\ "Y:\...\bin76543210\" /c /g /d /i /e /r /h /y /exclude:"Y:\...\exclude.txt"
returns error:
返回错误:
Invalid number of parameters
参数个数无效
Which also occurs when path names (containing spaces) are not enclosed by quotation marks. This however, is not the case. Paths (edited for readability) all correspond correctly. Syntax (as per Product Documentation - Xcopy) is also correct. Concerning OS is Windows XP Professional x32 SP3.
当路径名(包含空格)没有用引号引起来时,也会发生这种情况。然而,情况并非如此。路径(为了可读性而编辑)都正确对应。语法(根据产品文档 - Xcopy)也是正确的。关于操作系统是 Windows XP Professional x32 SP3。
Why is second cmd returning error and how is it to be solved? I am not looking for alternatives to xcopy (robocopy etc.).
为什么第二个cmd返回错误,如何解决?我不是在寻找 xcopy(robocopy 等)的替代品。
回答by dbenham
XCOPY is an old command harking back to the days of DOS. It looks like the /EXCLUDE option was never updated to support long file names. Ugh :-(
XCOPY 是一个古老的命令,可以追溯到 DOS 时代。看起来 /EXCLUDE 选项从未更新为支持长文件名。呃:-(
If you remove the quotes, then the text after the space is interpreted as an additional parameter, and you get the "Invalid number of parameters" error. If you keep the quotes, then it treats the quotes as part of the path, and reports it cannot find the file.
如果删除引号,则空格后的文本将被解释为附加参数,并且您会收到“参数数量无效”错误。如果您保留引号,那么它会将引号视为路径的一部分,并报告找不到该文件。
I believe you have three possible solutions:
我相信您有三种可能的解决方案:
1) Use the short 8.3 folder names in your path.
1) 在路径中使用简短的 8.3 文件夹名称。
Of course this cannot work if your volume has short names disabled.
当然,如果您的卷禁用了短名称,这将无法工作。
2) Use the SUBST command to create a drive alias for your troublesome path.
2) 使用 SUBST 命令为麻烦的路径创建驱动器别名。
subst Q: "Y:\path with spaces"
xcopy X:\ "Y:\...\bin76543210\" /c /g /d /i /e /r /h /y /exclude:Q:exclude.txt
subst Q: /d
This could be a problem if you don't know a drive letter that is free.
如果您不知道免费的驱动器号,这可能是一个问题。
3) (my favorite) Simply PUSHD do the troublesome path and run the command from there:-)
3)(我最喜欢的)只需 PUSHD 执行麻烦的路径并从那里运行命令:-)
pushd "Y:\path with spaces"
xcopy X:\ "Y:\...\bin76543210\" /c /g /d /i /e /r /h /y /exclude:exclude.txt
popd
See https://sevenx7x.wordpress.com/2009/01/02/xcopy-with-exclude-option-shows-cant-read-file/and http://forums.majorgeeks.com/showthread.php?t=54300for more information.
请参阅https://sevenx7x.wordpress.com/2009/01/02/xcopy-with-exclude-option-shows-cant-read-file/和http://forums.majorgeeks.com/showthread.php?t= 54300了解更多信息。
回答by JosefZ
/EXCLUDE:file
switch will not exclude the file specified. As per xcopy
command reference:
/EXCLUDE:file
switch 不会排除指定的文件。根据xcopy
命令参考:
/exclude:FileName1[+[FileName2][+[FileName3](…)]
Specifies a list of files. At least one file must be specified. Each file will contain search stringswith each string on a separate line in the file. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied.
/exclude:FileName1[+[FileName2][+[FileName3](…)]
指定文件列表。必须至少指定一个文件。 每个文件将包含搜索字符串,每个字符串在文件中的单独一行中。当任何字符串与要复制的文件的绝对路径的任何部分匹配时,该文件将被排除在复制之外。