windows 为什么 xcopy 在使用这些参数时不复制文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5183473/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:08:14  来源:igfitidea点击:

Why does xcopy not copy files when using these parameters?

windowscmdxcopy

提问by Saggio

I have a simple xcopy script that I'm running from the command line that reads a CSV file of directories and file names. I've used a very similar script with no problems before. Here is the script:

我有一个简单的 xcopy 脚本,我正在从命令行运行该脚本,该脚本读取目录和文件名的 CSV 文件。我以前使用过一个非常相似的脚本,没有任何问题。这是脚本:

Z:\HOME\>for /f "delims=, tokens=1,2,3,4" %i in (Z:\HOME\MissingImages.csv) do
echo f | xcopy "Y:\%j\%k\%l" "C:\Horizon\%j\%k\%l" >> Z:\HOME\MissingImagesLog.txt

However, it is not copying any of the files over Here is an entry from the log file:

但是,它不会复制任何文件,这是日志文件中的一个条目:

Does C:\Horizon\K
xcopy "pathname1/file" pathname2\file
bef500f.IMG specify a file name or directory name on the target (F = file, D = directory)? f 0 File(s) copied

It's finding the images because if I change the root directory to something else the script will just populate the log file with 0 File(s) copiedfor all entries, so the files are there and can be seen...

它正在查找图像,因为如果我将根目录更改为其他内容,脚本将只0 File(s) copied为所有条目填充日志文件,因此文件在那里并且可以看到......

Also, the Z:\drive is on a network and not local, but again I have used a very similar script across a network without problems (it just takes longer).

此外,Z:\驱动器在网络上而不是本地,但我再次在网络上使用了一个非常相似的脚本,没有问题(只是需要更长的时间)。

I've tried different options like /i, /s, etc. but I can't seem to get it to copy any files over.

我尝试了不同的选项,如/i/s等,但我似乎无法让它复制任何文件。

采纳答案by Saggio

Well, that's annoying; I found the issue. It looks like when I generated my CSV file, it put a space at the end of each line, so xcopy was looking for files that had a space after the extension.

好吧,这很烦人;我发现了这个问题。看起来当我生成我的 CSV 文件时,它在每行的末尾放了一个空格,所以 xcopy 正在寻找扩展名后有空格的文件。

The thing that was throwing me off was that it was finding the files, but couldn't copy them, making me think it was a network or xcopy issue.

让我失望的是它正在查找文件,但无法复制它们,让我认为这是网络或 xcopy 问题。

I just ran a sed script to remove the eol spaces and the xcopy script is now working as expected.

我刚刚运行了一个 sed 脚本来删除 eol 空间,xcopy 脚本现在按预期工作。

回答by iandallas

xcopy will also report 0 File(s) copiedif you use forward slashes "/" in paths instead of backslashes "\", though ONLY if you've enclosed the path in quotes.

xcopy 还会报告0 File(s) copied您是否在路径中使用正斜杠“/”而不是反斜杠“\”,但前提是您将路径用引号括起来。

  1. This fails with "0 File(s) copied"

    xcopy pathname1/file pathname2\file
    
  2. This fails with "Invalid number of parameters"

    xcopy pathname1\file pathname2\file
    
  3. This works just fine

    xcopy "pathname1/file" pathname2\file
    
  1. 这失败了“复制了 0 个文件”

    xcopy pathname1/file pathname2\file
    
  2. 这因“参数数量无效”而失败

    xcopy pathname1\file pathname2\file
    
  3. 这工作得很好

    xcopy pathname1\file.from pathname2\file.to
    

回答by pmod

It asks because it doesn't know whether you want to copy to directory (to be created) or you provide the full target pathname. This will ask:

它询问是因为它不知道您是要复制到目录(要创建)还是要提供完整的目标路径名。这会问:

xcopy pathname1\file.from pathname2\to\

However, adding slash will tell that you copy to directory:

但是,添加斜杠会告诉您复制到目录:

echo Y | xcopy pathname1\file.from pathname2\file.to

But I haven't found the way to tell explicitly that I want to copy and rename file, except

但是我还没有找到明确告诉我要复制和重命名文件的方法,除了

##代码##

I played a bit with your case (with for, doand xcopy) and found out that even if it asks Does SOMEFILE specify a file name or directory name on the target (F = file, D = directory)?it is provided with ffrom echoand it's copied successfully. Thus, it's not a problem with file/directory specifying, but with copying through network itself.

我玩了一下你的案例(使用fordoxcopy),发现即使它询问SOMEFILE 是否在目标上指定了文件名或目录名(F = 文件,D = 目录)?它提供了来自echo 的f并且它已成功复制。因此,指定文件/目录不是问题,而是通过网络本身复制的问题。