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]

[Main menu] [top] (Syntax) [Options] [Comments] [Examples] [See also] [File]

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.

[Main menu] [top] [Syntax] (Options) [Comments] [Examples] [See also] [File]

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.

[Main menu] [top] [Syntax] [Options] (Comments) [Examples] [See also] [File]

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 -

[Main menu] [top] [Syntax] [Options] [Comments] (Examples) [See also] [File]

See also:

  autoexec.bat
  batch files

[Main menu] [top] [Syntax] [Options] [Comments] [Examples] (See also) [File]

File:

  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.

[Main menu] [top] [Syntax] [Options] [Comments] [Examples] [See also] (File)


  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.