How do you iterate over each file in a directory with a .bat or .cmd file?
For simplicity please provide an answer that just echoes the filename or file path.
batch-filecmdfileloopswindows
How do you iterate over each file in a directory with a .bat or .cmd file?
For simplicity please provide an answer that just echoes the filename or file path.
Best Answer
Command line usage:
Batch file usage:
Update: if the directory contains files with space in the names, you need to change the delimiter the
for /f
command is using. for example, you can use the pipe char.Update 2: (quick one year and a half after the original answer :-)) If the directory name itself has a space in the name, you can use the
usebackq
option on thefor
:And if you need to use output redirection or command piping, use the escape char (
^
):