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.
This question is related to
windows
file
loops
batch-file
cmd
Use
for /r path %%var in (*.*) do some_command %%var
with:
I had some malware that marked all files in a directory as hidden/system/readonly. If anyone else finds themselves in this situation, cd into the directory and run for /f "delims=|" %f in ('forfiles') do attrib -s -h -r %f
.
Use
for /r path %%var in (*.*) do some_command %%var
with:
Alternatively, use:
forfiles /s /m *.png /c "cmd /c echo @path"
The forfiles command is available in Windows Vista and up.
I had some malware that marked all files in a directory as hidden/system/readonly. If anyone else finds themselves in this situation, cd into the directory and run for /f "delims=|" %f in ('forfiles') do attrib -s -h -r %f
.
Another way:
for %f in (*.mp4) do call ffmpeg -i "%~f" -vcodec copy -acodec copy "%~nf.avi"
Alternatively, use:
forfiles /s /m *.png /c "cmd /c echo @path"
The forfiles command is available in Windows Vista and up.
Easiest method:
From Command Line, use:
for %f in (*.*) do echo %f
From a Batch File (double up the % percent signs):
for %%f in (*.*) do echo %%f
From a Batch File with folder specified as 1st parameter:
for %%f in (%1\*.*) do echo %%f
Another way:
for %f in (*.mp4) do call ffmpeg -i "%~f" -vcodec copy -acodec copy "%~nf.avi"
Easiest method:
From Command Line, use:
for %f in (*.*) do echo %f
From a Batch File (double up the % percent signs):
for %%f in (*.*) do echo %%f
From a Batch File with folder specified as 1st parameter:
for %%f in (%1\*.*) do echo %%f
Source: Stackoverflow.com