Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
FOR--Examples
◄Syntax► ◄Notes►
────────────────────────────────────────────────────────────────────────────
FOR──Examples
Suppose you want to use the TYPE command to display the contents of all the
files in the current directory that have the extension .DOC or .TXT. To do
this and to use the replaceable variable %F, type the following command at
the command prompt:
for %f in (*.doc *.txt) do type %f
In this example, each file that has the .DOC or .TXT extension in the
current directory is substituted for the %F variable until the contents of
every file are displayed. To use this command in a batch file, you would
replace every occurrence of %F with %%F. Otherwise, MS-DOS ignores the
variable and displays an error message.
MS-DOS supports command switches, pipes, and redirection that you may want
to use with the specified command. For example, to redirect the output of
the previous example to PRN (the default printer port), you would type the
following command:
for %f in (*.doc *.txt) do type %f > prn:
♦