|
FOR
Runs a specified command for each file in a set of files.
FOR %variable IN (set) DO command [command-parameters]
%variable Specifies a replaceable parameter.
(set) Specifies a set of one or more files.
Wildcards may be used.
command Specifies the command to carry out for each
file.
command-parameters
Specifies parameters or switches for the
specified command.
To use the FOR command in a batch program, specify
%%variable instead of %variable. Variable names are case
sensitive, so %i is different from %I.
Examples
To display the contents of all the files in the current
directory that have the extension .doc or .txt using the
replaceable variable %f, type:
for %f in (*.doc *.txt) do type %f
This code will run through the set (A, B, C), when it gets
to B it will print the message: "B is in the set!"
FOR %%b in (A, B, C) DO IF %%b == B echo B is in the set!
This line will print the contents of C:\windows\desktop
FOR %%c in (C:\windows\desktop\*.*) DO echo %%c
Batch File Commands
|