I have a simple FOR loop inside of a batch file I'm creating that isn't quite working the way I'm expecting. The FOR loop iterates through lines of a text file, and on each iteration, I use an IF statement to make a quick comparison on the current line, and do some work if it evaluates to true. Here is the code:
SETLOCAL ENABLEDELAYEDEXPANSION
set /a sitecounts=1
set /a input=34
FOR /F "tokens=1,2 delims=^/" %%G IN (file.txt) DO (
IF %sitecounts% == %input% (set /a selectedsitepath=%logfilepath%W3SVC%%H)
set /a sitecounts=!sitecounts!+1
echo !sitecounts!
)
I'm running into a weird issue where, the sitecounts variable (my counter) actually increments properly with each loop (I prove this by echoing out the count with the last statement) -- BUT upon the next iteration %sitecounts% still shows that it has the value of '1', which was the initial value.
If I change the code to:
IF !sitecounts! == ...
...then the IF statement appears to treat that value as pure TEXT! I've set ENABLEDELAYEDEXPANSION to handle variables within loops, but not sure what to do next. Any help is appreciated!