我可以使用单个“复制”命令在 Windows 命令行上复制多个命名文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/922607/
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
Can I copy multiple named files on the Windows command line using a single "copy" command?
提问by Mark Carpenter
I'd like to copy several known files to another directory as a part of a post-build event, but don't want to have lines and lines of "copy [file] [destination] [switches]" in my build event. If possible, I'd like to list out the files I'd like to copy using a similar format: "copy [file 1] [file 2] [file 3] [etc...] [destination] [switches]". However, Windows doesn't seem to like this type of format. Any ideas? Thanks!
我想将几个已知文件复制到另一个目录作为构建后事件的一部分,但不希望在我的构建事件中有“复制 [文件] [目标] [开关]”的行和行。如果可能,我想使用类似的格式列出我想复制的文件:“复制 [文件 1] [文件 2] [文件 3] [等...] [目的地] [开关]” . 但是,Windows 似乎不喜欢这种类型的格式。有任何想法吗?谢谢!
回答by Ken White
You can use 'for' either in a batch file or directly from the command prompt:
您可以在批处理文件中或直接从命令提示符使用“for”:
for %I in (file1.txt file2.txt file3.txt) do copy %I c:\somedir\
Wildcards are supported in the filelist as well:
文件列表中也支持通配符:
for %I in (*.txt *.doc *.html) do copy %I c:\somedir\
For more info, just type for /? from a command prompt, or for a much easier to read help use Start->Help and Support and search for "For". On my XP Pro box, it was item 15 in the full text search results.
有关更多信息,只需输入 /? 从命令提示符,或者为了更容易阅读帮助,请使用开始->帮助和支持并搜索“For”。在我的 XP Pro 盒子上,它是全文搜索结果中的第 15 项。
回答by Kevin
XP and Vista replaced xcopywith robocopy, and it will do exactly what you want. The syntax for what you want feels backwards at first, but it does the job:
XP 和 Vista用robocopy替换了xcopy,它会完全按照您的要求执行。您想要的语法起初感觉倒退,但它可以完成工作:
robocopy source\folder a\dest\folder file1.exe file2.bat file3.dll file4.txt
回答by David Schmitt
Use the <Copy>
MSBuild task.