-1

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. I have a text file containing filenames.

What I'd like to do is something like

for x in textFile
    "python C:\main.py -s x"  # the command i want to run
  • What have you tried, and what have you searched for? This is an extremely easy task in batch that has been documented... basically everywhere. – SomethingDark Apr 22 '15 at 03:14
  • 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) – SomethingDark Apr 22 '15 at 03:17

1 Answers1

0
for /f %%x in (textFilename) do python C:\main.py -s %%x

would be the classic method - as a batch file.

reduce %% to % throughout if you are running directly from the prompt

or, more fully,

for /f "usebackqdelims=" %%x in ("textFilename") do python C:\main.py -s "%%x"
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Don't forget to include `"delims="` to grab the entire line, and `"usebackq"` in case the file path has a space in it somewhere. – SomethingDark Apr 22 '15 at 03:33