Author Options:

Batch. Reading multiple lines from a text file? Answered

I created a batch file, everytime it runs it saves a name and date to a log (log.txt). So everytime it gets more and more lines. I want to know how to read all the lines from File.txt (in another Batch file). my current script is:
@echo off
set /p txt= > File.txt
set /p txt2= >> File.txt
set /p txt3= >> File.txt
set /p txt4= >> File.txt
set /p txt5= >> File.txt
'and so on
echo %txt%
echo %txt1%
echo %txt2%
echo %txt3%
echo %txt4%
echo %txt5%

Every time i run it, it says "did not expect >>"
Please help


The forums are retiring in 2021 and are now closed for new topics and comments.

Best Answer 10 years ago

If you want to echo an entire txt file in a batch, simply type this: "type File.txt". That will output an entire txt file with no questions asked. If you want to loop through an entire txt file and actually do something else with the text (Like placing them in variables), have a look at the /f loop command here: http://ss64.com/nt/for_f.html .


Answer 10 years ago

thanks it sure helped