> Commands A-M
> Batch F
Loop through files (Recurse subfolders).
This command walks down the folder tree starting at [drive:]path,
and executes the DO statement against each matching file.
To use FOR in a batch program:
To use FOR from the command prompt:
- The command to carry out, including any command-line
- Specifies any parameters or switches that you want to use
with the specified command (if the specified command uses any
parameters or switches).
- The folder tree where the files are located.
- If the [drive:]path are not specified they will default
to the current drive:path.
- A set of one or more files. Wildcards may be used.
If (set) is a period character (.) then FOR will
loop through every folder.
- %variable or %%variable
- Represents a replaceable variable. The FOR command replaces
%%variable (or %variable) with each text string in the specified
set until the command (specified in the command parameter)
processes all the folders. Use %%variable to carry out the FOR
command within a batch program. Use %variable to carry out FOR
from the command prompt. (Do NOT use %0 through %9 to avoid
confusion with the command-line arguments passed to the batch
- Display help.
FOR - Loop through a set of files in one folder.
FOR /D - Loop through several folders.
FOR /L - Loop through a range of numbers.
FOR /F - Loop through items in a text file.
FOR /F - Loop through the output of a command.
FORFILES - Batch process multiple files.
GOTO - Direct a batch program to jump to a labelled line.
IF - Conditionally perform a command.
Equivalent Linux BASH commands:
cut - Divide a file into several columns.
for - Expand words, and execute commands.
eval - Evaluate several COMMANDS/arguments.
if - Conditionally perform a command.
m4 - Macro processor.
until - Execute commands (until error).
while - Execute commands.
To delete every .bak file in every subfolder starting
FOR /R C:\temp\ %%G IN (*.bak) DO del %%G
- Windows NT