批处理文件将多个目录中具有特定扩展名的文件复制到一个目录中
我是一名新手,所以请耐心等待...
我正在尝试使用批处理文件将分散在一个主目录的几个子目录中的所有 .doc
文件复制到另一个目录中。 我已设法从要复制的这些目录中获取所有文件(有数百个)的 filelist.txt
:
"C:\Main directory\sub directory" 目录 /b /s *.doc > “C:\主目录\子目录\filelist.txt”
我将使用什么脚本将它们复制到一个目录中? 我可以使用一些代码来实际从 filelist.txt
中获取这些文件名并复制它们吗?
作为参考,我查看了下面的问题,因为它看起来像是在做我想做的事情,但它对我不起作用。
,我真的很想理解这个概念,所以请为我分解代码,告诉我每个项目的作用,或者至少包含一个解释它的链接。
I'm a newbie, so bear with me...
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:\Main directory\sub directory"
dir /b /s *.doc > "C:\Main directory\sub directory\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.
Using xcopy to copy files from several directories to one directory
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
诸如此类的事情就是我转向 Powershell 的原因。 尝试一下,很有趣:
Things like these are why I switched to Powershell. Try it out, it's fun:
只需使用带有递归选项 /s 的 XCOPY 命令
即可使其“递归”
Just use the XCOPY command with recursive option
/s will make it "recursive"
在批处理文件解决方案中
代码的工作方式如下;
对于目录
c:\source
和子目录/R
中与模式(\*.xml)
for > 将文件名放入变量%%f
中,然后对于每个文件do
将文件copy %%f
复制到目标x: \\destination\\
刚刚在我的 Windows XP 计算机上测试了它,它对我来说就像一种享受。 但我将其输入到命令提示符中,因此我使用了单个
%f
变量名称版本,如上面链接的问题中所述。In a batch file solution
The code works as such;
for each file
for
in directoryc:\source
and subdirectories/R
that match pattern(\*.xml)
put the file name in variable%%f
, then for each filedo
copy filecopy %%f
to destinationx:\\destination\\
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.您还可以使用 vbscript
另存为 mycopy.vbs 并在命令行上
you can also use vbscript
save as mycopy.vbs and on command line
这可以使用以下命令来完成:
您还可以运行这些命令以使其简单
如果您愿意使用文件类型父文件夹名称进行复制,请尝试使用此命令
This can be done using this command:
you could also run these to make it simple
In case you are willing to copy with file types parent folder name try using this command
布兰登,简短而甜美。 还灵活。
希望这可以帮助。
我会在复制后添加一些检查(使用“||”),但我不确定“copy /v”在遇到错误时如何反应。
你可能想尝试这个:
作为复制行。 如果您从中得到了一些东西,请告诉我(无法测试复制失败的自动提款机..)
Brandon, short and sweet. Also flexible.
Hope this helps.
I would add some checks after the copy (using '||') but i'm not sure how "copy /v" reacts when it encounters an error.
you may want to try this:
As the copy line. let me know if you get something out of it (in no position to test a copy failure atm..)