FOR

The description below is from the book
DOS the Easy Way by Everett Murdock Ph.D.

CLICK HERE for information about downloading the book.

Type: Internal (2.0 and later)

Syntax:

FOR %%(variable) IN set DO (command)
or for interactive processing
FOR %%(variable) IN set DO (command)

Purpose: Performs repeated execution of commands (for both batch processing and interactive processing).

Discussion

%% variable can be any character.

set can be one or more file specifications.

The %%variable is set sequentially to each of the set entries. Then the DOS command specified after the DO is carried out. Typically set will include wildcard characters (? and *) to indicate a group of filenames. Then, %%variable is set to each matching filename. You can also use path designations for set.

This command provides a way to repeat DOS commands in a predetermined way (usually to tell DOS to carry out a command on each of the files named in the set specifications).

Any character except 0 through 9 can be used for %%variable (to avoid confusion with the %0-%9 batch parameters).

For more information on FOR and other batch commands, see Chapter 5, Using Batch Files, in the downloadable book DOS the Easy Way .

Example

To TYPE (display) the contents of every file in the current directory that has the filename extension TXT, enter

for %%X in (*.txt) do type %%X

If the program finds files on the disk that have the TXT extension, the command sets %%X to each of the TXT files, then displays the contents of each file.




Back to the Easy DOS Command Index