batch-file For Loops in Batch Files

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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`



Got any batch-file Question?