批处理文件 XCopy 命令
我有一个批处理文件,它循环遍历文本文件的内容并使用 xcopy 命令复制特定文件。
这是片段。
for /f %%a in (FilesToCopy.txt) do (
xcopy ..\..\Common\%%a Common\%%a /i /d /c /v /s /y /f
xcopy Common\%%a ..\..\Common\%%a /i /d /C /v /s /y /f
)
%%a 包含类似的值 图片\image1.jpg Images\image2.jpg
因此,当执行 xcopy 时,它看起来会
xcopy ..\..\Common\Images\image1.jpg Common\Images\image1.jpg /i /d /c /v /s /y
在执行时提示此消息
Does Common\Images\image1.png specify a file name
or directory name on the target
(F = file, D = directory)?
,似乎 /i 命令不起作用,或者我在这里缺少一些内容来抑制上面的消息。
I have a batch file which loops through a content of a text file and copies a specific file using xcopy command.
here's the snippet.
for /f %%a in (FilesToCopy.txt) do (
xcopy ..\..\Common\%%a Common\%%a /i /d /c /v /s /y /f
xcopy Common\%%a ..\..\Common\%%a /i /d /C /v /s /y /f
)
%%a contains values like
Images\image1.jpg
Images\image2.jpg
so when xcopy is executed it would look like
xcopy ..\..\Common\Images\image1.jpg Common\Images\image1.jpg /i /d /c /v /s /y
upon execute it would then prompt this message
Does Common\Images\image1.png specify a file name
or directory name on the target
(F = file, D = directory)?
it seems that the /i command doesn' work or i am missing something here to suppress the message above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您遗漏了帮助中关于
/I
的第二语句:您一次只能复制一个文件,因此
/I
不适用。您可以通过将
F
管道输入命令并抑制输出来解决此问题:(在非英语版本的 Windows 上不起作用;但这可能是您遇到的最不重要的问题,因为批处理对于带有空格的文件名已经失败:-))
您可以尝试构建一个要复制的长文件名列表:
不过,这需要对初始文件进行两次传递。当文件名列表超过 8190 个字符时,它会失败。
Well, you left out the second statement the help gives about
/I
:You are only ever copying one file at a time, so
/I
doesn't apply.You can probably hack-solving this by piping
F
into the command and suppressing output:(Won't work on non-English versions of Windows; but probably that's the least of your problems, given that the batch already fails for file names with spaces :-))
You could try building a single long list of file names to copy:
This requires two passes over the initial file, though. And it fails when the list of file names gets longer than 8190 characters.
目的地应该是路径,然后它不会询问:
在您的情况下,您可以在目的地上使用带有 %~p 的路径提取,因为您可能想保留它:
The destination should be a path, then it won't ask:
In your case, you can use path extraction with %~p on the destination since you may want to preserve that: