Iterate all files in a directory using a 'for' loop

Vhaerun picture Vhaerun · Sep 26, 2008 · Viewed 617.5k times · Source

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?

Answer

jop picture jop · Sep 26, 2008

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)