Batch For loop排除包含的文件名

时间:2013-04-24 13:47:31

标签: batch-file

我有一个简单的批处理文件,它将遍历所有* Test.htm文件并复制它们。有些文件将包含一个我不想复制的字符串。

FOR /R "C:\" %%g IN (*Test.htm) DO  (
echo %%g
)

我想要的伪代码:

@echo off
FOR /R "C:\" %%g IN (*Test.htm) DO ( 
   if %%g contains "Exclude" do nothing
else 
   copy...
)

1 个答案:

答案 0 :(得分:11)

对于文件名:

@echo off

FOR /R "C:\" %%g IN (*Test.htm) DO ( 
   (Echo "%%g" | FIND /I "Exclude" 1>NUL) || (
       Copy "%%g"...
   )
)

对于文件内容:

@echo off

FOR /R "C:\" %%g IN (*Test.htm) DO ( 
   (Type "%%g" | FIND /I "Exclude" 1>NUL) || (
       Copy "%%g"...
   )
)