Solved Resetting values everytime a loop restarts?

May 3, 2014 at 14:39:21
Specs: Windows 7
Im having trouble resetting values everytime a loop starts. How can I alter the code in s.bat so that the batch rechecks the txt file every single time the loop restarts rather than assuming the text file is still the same?


Contents of b.txt

c:\work\2014.doc
c:\work\abc.doc
c:\work\comp.doc
c:\work\2012.doc

contents of s.bat:

:loop
setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /F "tokens=*" %%A in (b.txt) do (
SET /A vidx=!vidx! + 1
set vare!vidx!=%%A
)
set vare

(The 1st line in b.txt gets deleted here)
goto loop

Everytime the loop restarts, there will be one less line. Problem is everytime the loop restarts it still sets the original four lines as vare1,vare2,vare3,vare4. Because the 4th line gets deleted at the end of the 1st loop, there should no %vare4% because now there are only 3 lines in b.txt and %vare1% should be c:\work\abc.doc but it still shows up as c:\work\2014.doc.


See More: Resetting values everytime a loop restarts?

Report •


#1
May 5, 2014 at 05:15:03
✔ Best Answer
There's probablv much more going on but here's a guess:

=======================================
=========================================================
setlocal ENABLEDELAYEDEXPANSION
:loop
set vidx=0
for /F "tokens=*" %%A in (b.txt) do (
SET /A vidx=!vidx! + 1
set vare!vidx!=%%A
)
set vare

(The 1st line in b.txt gets deleted here)
goto loop

=====================
M2 Golden-Triangle


Report •
Related Solutions


Ask Question