Solved resetting all variables in a txt file?

April 26, 2014 at 13:53:54
Specs: Windows 7
The file z.txt has five lines all set as variables.
Everytime one loop ends, the first line in z.txt is removed, however when the loop restarts , it is still setting the original five variables as variables despite z.txt having one less line. How can I refresh the loop everytime it restarts? If I delete the file z.txt at the end of the loop, the batch still sets the 5 variables once the loop starts again despite z.txt not existing anymore.Thank you.


set vidx=0
for /F "tokens=*" %%A in (z.txt) do (
SET /A vidx=!vidx! + 1
set vare!vidxf=%%A
set vare

(after removing the first line from z.txt here, the loop goes back to the start)

See More: resetting all variables in a txt file?

Report •

April 27, 2014 at 20:21:52
✔ Best Answer
It sounds like your vars are persisting (despite SETLOCAL), which can happen if the batch exits due to user-break or an error (such as you have in this line:
set vare!vidxf=%%A
which is missing an exclam.)
If you type "set" at the command prompt, and you see the variables, then those values will override the local ones (child process inherits parents environment).
To clear these vars for a clean start, exit the command-prompt then re-enter it
Aside from that, I'm clueless as to what you're trying to do - why do you need to delete lines from z.txt? why reset the same 4..3..2..1 variables to the same values as you go through the loops? If you just want to assign vars from z.txt, all you need is your main code as written - no further (outer) loop or z-line-deletes required.

Report •
Related Solutions

Ask Question