Home
> Commands A-M
> Batch F
FOR /R
Description
| Syntax
| Parameters
| Switches
| Related
| Notes
| Examples
| Errorlevels
| Availability
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.
Syntax
FOR /R
/?
To use FOR in a batch program:
FOR /R
[[drive:]path]
%%variable
IN (set)
DO command
[command-parameters]
To use FOR from the command prompt:
FOR /R
[[drive:]path]
%variable
IN (set)
DO command
[command-parameters]
Parameters
- command
(NT4)
- The command to carry out, including any command-line
parameters.
- command-parameters
(NT4)
- Specifies any parameters or switches that you want to use
with the specified command (if the specified command uses any
parameters or switches).
- )
- [[drive:]path]
(NT4)
- The folder tree where the files are located.
- If the [drive:]path are not specified they will default
to the current drive:path.
- (set)
(NT4)
- 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
(NT4)
- 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
file).
Switches
- /?
(NTXP)
- Display help.
Related
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.
Notes
none.
Examples
To delete every .bak file in every subfolder starting
at C:\temp:
FOR /R C:\temp\ %%G IN (*.bak) DO del %%G
Errorlevels
none.
Availability
- Internal
-
- DOS
-
none
- Windows
-
none
- Windows NT
-
NT4
NT2000
NTXP
NT2003
Last Updated: 2003/07/28
Direct corrections or suggestions to:
Rick Lively