Quincy Center for Technical Education
Computer Technology Department

for

Runs a specified command for each file in a set of files.

You can use the for command within a batch program or directly from the command prompt.

To use for in a batch program, use the following syntax:

for %%variable in (set) do command [command-parameters]

To use for from the command prompt, use the following syntax:

for %variable in (set) do command [command-parameters]

Parameters

%%variable or %variable

Represents a replaceable parameter. The for command replaces %%variable (or %variable) with each text string in the specified set until the command (specified in the command-parameters) processes all of the files. Use %%variable to carry out the for command within a batch program. Use %variable to carry out for from the command prompt. Variable names are case sensitive.

(set)

Specifies one or more files or text strings that you want to process with the specified command. The parentheses are required.

command

Specifies the command that you want to carry out on each file included in the specified set.

command-parameters

Specifies any parameters or switches that you want to use with the specified command (if the specified command uses any parameters or switches).

If command extensions are enabled (the default setting in Windows 2000), additional forms of the for command are supported.