Name
for
Synopsis
Repeat a specified command any number of times.
Syntax
for [/d] %%variablein (set) docommand[arguments] for /r [path] %%variablein (set) docommand[arguments] for /r [path] %%variablein (set) docommand[arguments] for /l %%variablein (start,step,end) docommand[arguments]
(in and do are not options, but
rather simply part of the syntax; if omitted, an error will occur.)
Description
Use this command to create loops in a batch file. A
for loop is a programming construct that allows
you to repeat a command for a list of items (such as filenames). 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:
-
command[arguments] The command to execute or the program filename to run. This can be anything you’d normally type at a command prompt;
argumentsare the options, if any, to pass to the command.-
%%variable A one-letter variable name that is assigned, one by one, to the elements listed in
set. Althoughvariableis treated like a standard environment variable (see set, earlier in this chapter), it’s name is case sensitive (%%jis different than%%J) and can only be one letter long. Note also the use of two preceding percent signs. If theforcommand is issued directly from the command prompt (and not from within a batch file), use only one percent sign here.-
set The sequence of elements through which the
forcommand cycles. Elements are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access