1.

Solve : AutoIncrement variable within loop?

Answer»

I WANT to increment the value of a variable within a loop.
========================================
set x=1
for /f "skip=2 delims="" tokens=1" %%a in ('find /v "" dir.txt')
do (
set /a x= x + 1
echo %x%
pause
)
========================================
But when I execute this I am getting the O/p as 1 printed in loop insted of the incremented value. I CHECKED the value of x in cmd prompt as
c:\>set x
This gave me the correct incremented value.

Why is it no printing the incremented value in the screen when the batch file is executing.
Plz helpYour code produced a syntax error on my MACHINE. What is it you're trying to do?

The FIND command has a /c switch for counting.

The command processor is very quirky when it COMES to % variables within a FOR. If you do find a SOLUTION, please post it. Should be interesting to see.



Discussion

No Comment Found