跳过for循环的一部分

时间:2014-04-27 08:52:49

标签: windows batch-file for-loop goto

我正在尝试创建一个批处理脚本,该脚本将记录找到的hello.txt实例的位置。问题是我可能hello.txt和/或%workingroot%中都有%startingloc%的一个副本。

在脚本中,我尝试检查它是否在%workingroot%%startingloc%。但是当它被触发并转到标签:skip时,它似乎忘记了它仍处于for循环中并继续沿着脚本继续。

for /f "delims=" %%f in ('dir /s /b /a-d "%searchloc%\hello.txt"') do (
if "%%f"=="%workingroot%" goto skip
if "%%f"=="%startingloc%" goto skip
echo Instance found.
set /a foundd=!foundd!+1
echo %%f>> "%templl%\wefound.txt"
:skip
)

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:3)

for /f "delims=" %%f in ('dir /s /b /a-d "%searchloc%\hello.txt"') do (
 if not "%%f"=="%workingroot%" if not "%%f"=="%startingloc%" (
  echo Instance found.
  set /a foundd=!foundd!+1
  echo %%f>> "%templl%\wefound.txt"
 )
)

应该适合你。