Windows – Iterate all files in a directory using a ‘for’ loop

batch-filecmdfor-loopwindows

How can I iterate over each file in a directory using a for loop?

And how could I tell if a certain entry is a directory or if it's just a file?

Best Solution

This lists all the files (and only the files) in the current directory:

for /r %i in (*) do echo %i

Also if you run that command in a batch file you need to double the % signs.

for /r %%i in (*) do echo %%i

(thanks @agnul)