batch-fileFor Loops in Batch Files


Syntax

  • for /l %%p in (startNumber, increment, endNumber) do command
  • for /f %%p in (filename) do command
  • for /f %%p in ("textStrings") do command
  • for /f %%p in ('command') do command
  • for /r drive:\path %%p in (set) do command
  • for /d %%p in (directory) do command

Remarks

The for command accepts options when the /f flag is used. Here's a list of options that can be used:

  • delims=x Delimiter character(s) to separate tokens

  • skip=n Number of lines to skip at the beginning of file and text strings

  • eol=; Character at the start of each line to indicate a comment

  • tokens=n Numbered items to read from each line or string to process

  • usebackq Use another quoting style:

    Use double quotes for long file names in "files"

    Use single quotes for 'textStrings'

    Use back quotes for `command`