0

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
John Boe
  • 3,501
  • 10
  • 37
  • 71
  • possible duplicate of [How do you loop through each line in a text file using a windows batch file?](http://stackoverflow.com/questions/155932/how-do-you-loop-through-each-line-in-a-text-file-using-a-windows-batch-file). SO > computing.net – bzlm Feb 19 '12 at 22:02
  • See also http://stackoverflow.com/questions/4389923/batch-read-lines-from-a-file-having-spaces-in-its-path – indiv Feb 19 '12 at 22:18

1 Answers1

2

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).

reuben
  • 3,360
  • 23
  • 28