Difference between revisions of "For loop in CMD parsing entries in a TXT file"
From Tech-Wiki
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Microsoft]] | [[Category:Microsoft]] | ||
+ | '''[[Microsoft#Misc|Back to Misc]]''' | ||
+ | |||
+ | |||
for %a in (host1 host2 host3) do Ping %a | for %a in (host1 host2 host3) do Ping %a | ||
+ | The same, but reading from file instead: | ||
for /F %a in (hosts.txt) do Ping %a | for /F %a in (hosts.txt) do Ping %a | ||
+ | |||
+ | Now, getting the list dynamically from another command's output: | ||
+ | for /F %a in ('dir /b "D:\my videos"') do ffmpeg %a --title %a | ||
+ | |||
+ | If your file contains spaces, then this amend would be required: | ||
+ | for /F "tokens=* delims=," %a in (movies.txt) do vlc %a |
Latest revision as of 15:11, 6 December 2020
for %a in (host1 host2 host3) do Ping %a
The same, but reading from file instead:
for /F %a in (hosts.txt) do Ping %a
Now, getting the list dynamically from another command's output:
for /F %a in ('dir /b "D:\my videos"') do ffmpeg %a --title %a
If your file contains spaces, then this amend would be required:
for /F "tokens=* delims=," %a in (movies.txt) do vlc %a