Skip to content

Batch Script For Loop through Files

Learn how to use the for loop in Windows batch scripts to iterate through files in a directory with syntax like for %a in (path\*) do command.

For Loop through Files

To loop through files using the for loop, you must use % followed by a single letter, such as %a.

Example

An example of a for loop for looping through files at a given location.

for %a in (D:\documents\*) do @echo %a
Navigation