使用xcopy通过* .extension复制多个文件 [英] Copying multiple files by *.extension with xcopy
本文介绍了使用xcopy通过* .extension复制多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个批处理脚本,以将所有.doc
,.pdf
,.xls
等从磁盘复制到Pendrive.
我当前的代码如下:
@echo off
Title ""
::All Docs
XCOPY C:\*.doc W:\xdatabase /C /S /I /F /H > W:\database\XC\AllInf.txt
::All PDFs
XCOPY C:\*.pdf W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All WRI
XCOPY C:\*.wri W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All TXT
XCOPY C:\*.txt W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All PPT
XCOPY C:\*.ppt W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All XLS
XCOPY C:\*.xls W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
问题是:如何添加更多扩展名,但避免代码中的所有重复项?
解决方案
在所有编程语言中始终为true:如果必须连续执行多次操作,请使用循环.
@echo off
Title ""
for %%e in (doc pdf wri txt ppt xls) do (
XCOPY "C:\*.%%e" W:\xdatabase /C /S /I /F /H > W:\database\XC\AllInf.txt
)
在批处理脚本中,for
循环可能很棘手.一个方便的指南在这里: http://ss64.com/nt/for.html >
I'm making a batch script to copy all .doc
, .pdf
, .xls
etc from disk to a pendrive.
My current code below:
@echo off
Title ""
::All Docs
XCOPY C:\*.doc W:\xdatabase /C /S /I /F /H > W:\database\XC\AllInf.txt
::All PDFs
XCOPY C:\*.pdf W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All WRI
XCOPY C:\*.wri W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All TXT
XCOPY C:\*.txt W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All PPT
XCOPY C:\*.ppt W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
::All XLS
XCOPY C:\*.xls W:\xdatabase /C /S /I /F /H >> W:\database\XC\AllInf.txt
The question is: How can I add more extensions but avoid all that duplication in the code?
解决方案
Always true, in all programming languages: If you have to do a thing multiple times in a row, use a loop.
@echo off
Title ""
for %%e in (doc pdf wri txt ppt xls) do (
XCOPY "C:\*.%%e" W:\xdatabase /C /S /I /F /H > W:\database\XC\AllInf.txt
)
The for
loop can be tricky in batch scripting. A handy guide is here: http://ss64.com/nt/for.html
这篇关于使用xcopy通过* .extension复制多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文