Thist post is about how to use for loop in DOS programming.

Loop are used to execute block of code multiple times.

DOS loop

Loops are easy to write and to execute the code number of times, with each time with different values.

DOS support following syntax for loop

FOR element in list
 DO commandtoexecute

element is an character to pick an item from list

Do command tells to execute the command for every iteration

how iterate files in a directory using for loop

Let’s see an example .

Here is an command to execute in a command line

for /r %k in (*.\k) do echo %k

To run in batch file, we have to include

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

We can use for loop with following

For /r - recursive files and sub folders FOR /D - iterates folders FOR /L - Iterate loop of numbers