tldr/pages/windows/for.md

25 lines
830 B
Markdown
Raw Permalink Normal View History

2021-12-12 14:29:08 +00:00
# for
> Conditionally execute a command several times.
> More information: <https://docs.microsoft.com/windows-server/administration/windows-commands/for>.
2021-12-21 12:48:58 +00:00
- Execute given commands for the specified set:
2021-12-12 14:29:08 +00:00
`for %{{variable}} in ({{item_a item_b item_c}}) do ({{echo Loop is executed}})`
2021-12-21 12:48:58 +00:00
- Iterate over a given range of numbers:
2021-12-12 14:29:08 +00:00
`for /l %{{variable}} in ({{from}}, {{step}}, {{to}}) do ({{echo Loop is executed}})`
2021-12-21 12:48:58 +00:00
- Iterate over a given list of files:
2021-12-12 14:29:08 +00:00
`for %{{variable}} in ({{file_a.ext file_b.ext file_c.ext}}) do ({{echo Loop is executed}})`
2021-12-21 12:48:58 +00:00
- Iterate over a given list of directories:
2021-12-12 14:29:08 +00:00
`for /d %{{variable}} in ({{directory_a/ directory_b/ directory_c/}}) do ({{echo Loop is executed}})`
2021-12-21 12:48:58 +00:00
- Perform a given command in every directory:
2021-12-12 14:29:08 +00:00
`for /d %{{variable}} in (*) do (if exist %{{variable}} {{echo Loop is executed}})`