Example usage for for.
for %F in (*.log) do @echo %FRepeat a command over files, parsed text, directories or a numeric range.
for {%% | %}<variable> in (<set>) do <command> [<commandlineoptions>]The linked Microsoft Learn article is the upstream authority. Availability may depend on Windows release, role, optional feature or interactive tool context.
Example usage for for.
for %F in (*.log) do @echo %F| Option / clause | Description |
|---|---|
%variable / %%variable | Use one percent sign at an interactive prompt and two in batch files. |
/d | Iterate over matching directories. |
/r [<path>] | Walk a directory tree recursively. |
/l | Iterate over a numeric range in the form (start,step,end). |
/f [<options>] | Parse files, command output or strings into tokens. |
in (<set>) / do <command> | Provide the item set and the command to run for each item. |
{%% \ | Microsoft documents this argument or subcommand; check the linked reference for its required format and context. |
<commandlineoptions> | Microsoft documents this argument or subcommand; check the linked reference for its required format and context. |
/? | Display command help or the supported command-line usage. |
<variable> | Microsoft documents this argument or subcommand; check the linked reference for its required format and context. |
Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.