Jump to content
Toggle menu
  • 51 articles
  • 24 files
  • 4 users
  • 750 edits
Tech-Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

For loop in CMD parsing entries in a TXT file

From Tech-Wiki


Script and automation reference for For loop in CMD parsing entries in a TXT file.

Script

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

See also