John Boe
John Boe

Reputation: 3621

Reading of file line by line in batch

I have found this example here:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ("GEN 0 GENERAL.html") do (
echo do my commands on %%a
pause
)
pause

I should read file line by line. My goal is to read and print whole line, not just one or two tokens. For me this does not work. Any idea why? I got this output: do my commands on GEN 0 GENERAL.html Press any key to continue...

Solved:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= usebackq" %%a in ("GEN 0 GENERAL.html") do (
echo do my commands on %%a
pause
)
pause

Upvotes: 0

Views: 2657

Answers (1)

reuben
reuben

Reputation: 3370

Add usebackq to your options list, after the tokens and delims options:

"tokens=* delims= usebackq"

As you have it written, the double quotes around the filename are causing it to be interpreted as a string (and not the name of file containing strings).

Upvotes: 2

Related Questions