Command: for
FOR runs a specified command for each file in a set of files.
FOR is a BATCH-FILE / AUTOEXEC.BAT command.
It can also be used in command line.
Syntax:
FOR %variable IN (set) DO command [cmd-parameters]
FOR %%variable IN (set) DO command [cmd-paramters]
Options:
%variable A name for the parameter that will be replaced
with each file name.
%%variable A name for the parameter that will be replaced
with each file name.
(set) Specifies a set of one or more files. Wildcards
and ? may be used.
command Specifies the command to run for each file.
cmd-parameters Specifies parameters or switches for the
specified command.
Comments:
To use the FOR command in a batch program, specify %%variable instead
of %variable.
FOR is a command internal to command.com and needs no other file
in order to work.
Examples:
IN A .BAT FILE / AUTOEXEC.BAT:
Displays all the text files in the current directory, one after
another:
FOR %f in (*.txt) DO more %f
The following two commands list all files starting with an "a". The
list starts with "---start---" and ends with "---end---". The "-"
sign at the beginning and at the end of each line comes from "DO
ECHO - %f -".
ECHO off
FOR %f IN (---start--- a*.* ---end---) DO ECHO - %f -
See also:
autoexec.bat
batch files
------------------------------------------------------------------------------
Copyright (C) 2003 Robert Platt, updated 2007 by W. Spiegl.
This file is derived from the FreeDOS Spec Command HOWTO.
See the file H2Cpying for copying conditions.