|
Answer» I am trying to use the variable outside of the For loop. The echo inside the loop GIVES the result as expected. it is not working when i echo the variable outside of the loop. below is the script. Please let me know what am MISSING. THANK you!
Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION SET x=0 FOR /f "tokens=*" %%a in ('dir "%INPATH%*_Out.txt" /b') DO ( SET /a x+=1& SET /a cnt+=1& SET Fname%x%=%%a& SET FDATE%x%=!Fname%x%:~0,8! ECHO %x% !cnt! !Fname%x%! !Date%x%! )
set z=3 ECHO !FDate%z%!Take out this line and try the code you have shown:
Code: [Select]set z=3 Copy what you see on the console into a reply.ECHO is on.0 20140609215426_Out.txt 20140609 0 20140610215426_Out.txt 20140610 0 20140614215426_Out.txt 20140614 0 20140617215426_Out.txt 20140617
modified the below line, now it seems fine. Thank you!
Code: [Select]SET /a x=!x!+1& I missed that it was z instead of the x variable.
All occurrences of %x% within the loop have to be !x! if you are changing the variable and using it within the loop.
|