How do you loop through each line in a text file using a windows batch file?

batch-file, windows

Solution

I needed to process the entire line as a whole. Here is what I found to work.

for /F "tokens=*" %%A in (myfile.txt) do [process] %%A

The tokens keyword with an asterisk (*) will pull all text for the entire line. If you don't put in the asterisk it will only pull the first word on the line. I assume it has to do with spaces.

For Command on TechNet

If there are spaces in your file path, you need to use `usebackq`. For example.

for /F "usebackq tokens=*" %%A in ("my file.txt") do [process] %%A

Problem

I would like to know how to loop through each line in a text file using a Windows batch file and process each line of text in succession.

Original source

Related problems