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.
FOR %variable IN (set) DO command [cmd-parameters]
FOR %%variable IN (set) DO command [cmd-paramters]
%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
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.
IN A .BAT FILE / AUTOEXEC.BAT:
Displays all the text files in the current directory, one after
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 -".
FOR %f IN (---start--- a*.* ---end---) DO ECHO - %f -
Please read this command's lsm file also.
You will find the updated version (internet) here and
the version described in this manual page here.
The lsm file contains information about the name of the programmer,
the download site, and some other command related information.
Copyright © 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.