忽略批处理文件中的模式 [英] Ignore patterns in batch files
问题描述
我正在处理批处理脚本,该脚本需要将所有文件从一个文件夹复制到另一个文件夹,但有一些例外。
如何忽略以 Proxy.dll结尾的文件。
I'm working on batch script that needs to copy all files from one folder to another with a few exceptions. How do I ignore files ending with "Proxy.dll".
基本上,我想知道是否有可能基于其一部分忽略文件
Basically, I would like to know is it possible to ignore files based on part of its name when using xcopy.
这是我的脚本
xcopy C:\\WebService %InstallFolder%\ /EXCLUDE:XcopyExclude.txt /e /s /k /r /h /y /i >>Setup.log
这是XcopyExclude.txt
And this is XcopyExclude.txt
.config\
Properties
Obj
*Proxy.dll
感谢
推荐答案
robocopy
命令提供了更智能的排除功能(开关 / XD
和 / XF
)比 xcopy
做的多,您可以将其用于任务:
The robocopy
command provides a more intelligent exclusion feature (switches /XD
and /XF
) than xcopy
does, which you could use for your task:
robocopy "C:\WebService" "%InstallFolder%" "*.*" /XD "*.config" "Properties" "Obj" /XF "*Proxy.dll" /E /S /FP /NJH /NJS /NS /NC /NDL /NP /LOG+:"Setup.log"
所有以开头的开关/ N
和 / FP
开关控制记录的输出的外观,因此它与<$ c的输出非常相似$ c> xcopy 命令。
All the switches starting with /N
as well as the /FP
switch control the appearance of the logged output, so that it is quite similar to that of the xcopy
command.
如果您坚持使用 / EXCLUDE
选项的 xcopy
:这不支持 *
或?
,但仅是文字(不区分大小写)字符串。但是,您可以提前在 * Proxy.dll
中解析通配符。给定您具有以下内容的文件 XcopyExclude.txt
:
If you insist on the /EXCLUDE
option of xcopy
: this does not support wild-cards like *
or ?
but literal (case-insensitive) strings only. However, you could resolve the wild-card in *Proxy.dll
in advance. Given you have a file XcopyExclude.txt
with the following content...:
.config\
\Properties\
\Obj\
...(假设所有这些都是(部分)目录名),您可以将此内容复制到一个临时文件中,并附加已解析的 * Proxy.dll
部分,在实际复制活动之前:
...(assuming that all these items are (partial) directory names), you could copy this content to a temporary file and append the resolved *Proxy.dll
part, before the actual copying activity:
rem // Prepare exclusion list file:
copy /Y "XcopyExclude.txt" "XcopyExclude.tmp"
>> "XcopyExclude.tmp" (
for /R "C:\WebService" %%E in ("*Proxy.dll") do (
echo(\%%~nxE
)
)
rem // Perform copying action:
xcopy "C:\WebService" "%InstallFolder%" /E /S /K /R /H /Y /I /EXCLUDE:XcopyExclude.tmp >> "Setup.log"
rem // Clean up temporary list file:
del "XcopyExclude.tmp"
假设源目录树中有一个名为 AnyProxy.dll
的文件,文件<$的相关条目c $ c> XcopyExclude.tmp 将是 \AnyProxy.dll
。请注意,该项目名为 AnyProxy.dll。任何
也会被意外排除。
Supposing there is a file called AnyProxy.dll
in the source directory tree, the related entry for file XcopyExclude.tmp
would be \AnyProxy.dll
. Note that an item called AnyProxy.dll.any
would be accidently excluded as well.
这篇关于忽略批处理文件中的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!