Question

I'm trying to create a batch script that will record the locations of found instances of hello.txt. The problem is that I could have one copy of hello.txt in both %workingroot% and/or %startingloc%.

In the script, I tried to make it check whether or not it was in %workingroot% or %startingloc%. But when it is triggered and goes to the label :skip, it appears to forget that it was still in a for loop and just continues on down the script.

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
)

Is there any way to get around this?

Was it helpful?

Solution

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"
 )
)

should work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top