批处理文件 将具有特定扩展名的文件从多个目录复制到一个目录中 [英] batch file Copy files with certain extensions from multiple directories into one directory
问题描述
我是新手,请耐心等待...
I'm a newbie, so bear with me...
我正在尝试使用批处理文件将分散在一个主目录的多个子目录中的所有 .doc
文件复制到另一个目录中.我已经设法从我想要复制的这些目录中获取所有文件(有数百个)的 filelist.txt
:
I am trying to copy all .doc
files that I have scattered throughout several subdirectories of one main directory into another directory using a batch file. I have managed to get a filelist.txt
of all the files (there are hundreds) out of these directories that I want to copy using:
"C:主目录子目录"dir/b/s *.doc >"C:主目录子目录filelist.txt"
我将使用什么脚本将它们复制到一个目录中?我可以使用一些代码来实际从 filelist.txt
中获取这些文件名并复制它们吗?
What script would I use to xcopy those into one directory? Can I use some code that actually grabs those file names from filelist.txt
and xcopies them?
作为参考,我查看了下面的问题,因为它看起来像是在做我想做的事情,但对我不起作用.
For reference, I looked at the question below because it looked like it was doing what I want to do, but it didn't work for me.
另外,我真的很想理解这个概念,所以请分解代码让我告诉我每个项目的作用,或者至少包含一个解释它的链接.
Also, I would really like to understand this concept, so please break down the code for me to tell me what each item does, or at least include a link that will explain it.
推荐答案
在批处理文件中的解决方案
In a batch file solution
for /R c:source %%f in (*.xml) do copy %%f x:destination
代码是这样工作的;
对于目录 c:source
和子目录 /R
中匹配模式 (*.xml) 的每个文件
for
把文件名放在变量 %%f
中,然后对于每个文件 do
复制文件 copy %%f
到目标 >x:\目的地\
for each file for
in directory c:source
and subdirectories /R
that match pattern (*.xml)
put the file name in variable %%f
, then for each file do
copy file copy %%f
to destination x:\destination\
刚刚在我的 Windows XP 计算机上测试了它,它对我来说就像一种享受.但是我将它输入到命令提示符中,所以我使用了单个 %f
变量名称版本,如上面链接的问题所述.
Just tested it here on my Windows XP computer and it worked like a treat for me. But I typed it into command prompt so I used the single %f
variable name version, as described in the linked question above.
这篇关于批处理文件 将具有特定扩展名的文件从多个目录复制到一个目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!