1.

Solve : FOR Command Help?

Answer»

The CODE I write is as below

set n=1
set /A n =n + 2
echo %n%
FOR %%c in (E:\Temp\Temp_Bat\testvec\*.*) DO (
echo %%c
@ECHO off
set /A n =n + 1
echo %n%
)
pause

The value of n is updated to 3 before the for loop.
But, I want the value of n should be incremented by 1 at each time inside the for loop. But Its not happening.

How can I do this?If you move the echo %n% statement past the CLOSE paren of the FOR, you will see that it does in fact work.

I can't explain it but if you find an explanation, please post it. Should make for some interesting reading. To make this work correctly we must force the variable %var% to be evaluated during each iteration, using the CALL :subroutine mechanism:

syntax-FOR-List of numbers
FOR /L %%parameter IN (start,step,end) DO command

******************************

echo off
cls
set xx=1
set var=0
for /L %%s in (1,1,10) do (
call :sub1
)
GOTO :end

:sub1
set /a var=var+xx
echo %var%
goto :eof

:end
echo "OK"


The same will work with files

syntax-FOR-File contents
FOR /F ["options"] %%parameter IN (filenameset) DO commandHi,
I want to display the folder content along with the incrementing the varaible.
For exmp
FOR %%c in (E:\Temp\Temp_Bat\testvec\*.*) DO (
/* If testvec contains 3 text files SAY 1.txt,2.txt,3.txt and n=3 before the loop

output should be

1.txt n=4
2.txt n=5
3.txt n=6

*/

the loop should execute for 3 times along with the varaibles should be increment ed 1 @ each time.

Can u plz will help in this regard

Thanx in advance




Discussion

No Comment Found