How to read text file from start to end twice

September 26, 2015 at 19:20:36
Specs: Windows 7
Hi ,

I am working on a batch script that reads in items line by line from a text file 'Source.txt' like below

for /f "tokens=*" %%c in (Source.txt) do (


)

then I have to read the same text file from start to finish again at some point in the same batch file but if I do

for /f "tokens=*" %%c in (Source.txt) do (

)

It does not do anything. I think because the first time this file was read, the counter or pointer moved from first item to EOF. So second loop does not get executed.

How can I reset the File Counter or pointer to start of file again, so I can read the file from start to finish the second time.


See More: How to read text file from start to end twice

Report •

#1
September 26, 2015 at 20:19:35
To check if the second loop gets executed, use Echo %%c to see if it outputs anything. It shouldn't matter how many times you loop through a file in a batch script, what might matter though is what kind of commands are IN the loop and what commands are executed prior to the loop (Providing the entire script, or parts of it helps a lot when it comes to helping you solve issues).

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

#2
September 27, 2015 at 06:19:13
Hard for me to troubleshoot your script without seeing it.

=====================

M2 Get custom script or take private lessons


Report •

#3
September 27, 2015 at 09:47:39
Also, make sure you're not using the same %%c token while in the original FOR loop. (Another case of show code that replicates the issue, or don't expect valid responses.)

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question