Name

for

Synopsis

Use this command to repeat a specified command any number of times. You specify an arbitrary variable name and a set of values to be iterated through. For each value in the set, the command is repeated. The options used by for are the following:

for [/d] %variable in (set) do command [arguments]
for /r [path] %variable in (set) do command [arguments]
for /l %variable in (start,step,end) do command 
   [arguments]

Option

Description

command [ arguments ]

The command to execute or the program filename to run.

%variable

A one-letter variable name that is assigned, one-by-one, to the elements listed in set. When used in a batch file, the variable name must be preceded by two percent signs.

set

The sequence of elements through which the for command cycles. Elements are separated with spaces, and can be files, strings, or numbers. Use the /l option for the more traditional start,step,end format.

/d

Instructs for to match against directory names instead of filenames if set contains wildcards. Can't be used with the /l or /r options.

/l

Specifies that set takes the form of start,step,end, allowing you to specify a range of numbers and an increment instead of having to list each element.

/r [ path ]

Recursively executes command for each directory and subdirectory in path. If path is omitted, the current directory is used. Without /r, files specified in set only relate to the current directory. If set is just a single period (.), for will simply list ...

Get Windows XP Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.