使用xcopy将文件从多个目录复制到一个目录 [英] Using xcopy to copy files from several directories to one directory
问题描述
是否可以使用xcopy仅通过一个xcopy命令将文件从多个目录复制到一个目录中?
Is it possible to use xcopy to copy files from several directories into one directory using only one xcopy command?
假设我有目录树
root \ Source \ Sub1 \ Sub2
root\Source\Sub1\Sub2
我想将所有.xml文件从目录root \ Source(包括子文件夹)复制到root \ Destination.我不想复制文件夹结构,仅复制文件.
I want to copy all .xml files from the directory root\Source including sub folder to root\Destination. I don't want to copy the folder structure, just the files.
推荐答案
正如DandDI所说,您不需要xcopy.声明很有帮助.但是,您也不需要说明dir命令的处理结果,此命令会更好地帮助您
As DandDI said, you don't need xcopy. for statement helps much. However, you don't need to state process outcome of dir command as well, this command helps better
for /R c:\source %f in (*.xml) do copy "%f" x:\destination\
顺便说一句,当您从批处理文件中使用它时,您需要在变量%f前面添加备用%,因此您的命令行应该是:
By the way, when you use it from a batch file, you need to add spare % in front of variable %f hence your command line should be;
for /R c:\source %%f in (*.xml) do copy %%f x:\destination\
批量使用时
- 应将%f用双引号引起来,否则将无法复制带有空格的文件名
这篇关于使用xcopy将文件从多个目录复制到一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!