In another post, I explained how to use the FOR command to loop through a range of numbers. This time I want to show some other interesting functionalities of the FOR command:

FOR – Loop through a set of files in one folder
FOR /R – Loop through files (recurse subfolders)
FOR /D – Loop through several folders
FOR /L – Loop through a range of numbers
bash

1. Loop through a set of files in one folder
FOR %%G IN ("C:\file1.txt" "C:\File2.txt") DO copy %%G C:\bck\
the above command will copy file1.txt and file2.txt into C:\bck\

2. List all txt files in C:\ (recursively)
@echo off
FOR /R "C:\" %%G in (*.txt) DO Echo %%G
3. List all directories and subdirectories in C:\ (recursively)
@echo off
FOR /D /r %%G IN ("C:\") DO echo %%G

4. Loop through a range of numbers
take a look at loop in batch files

Gg1