2021-12-12 14:29:08 +00:00
|
|
|
# for
|
|
|
|
|
|
|
|
> Conditionally execute a command several times.
|
2022-10-04 16:06:23 +01:00
|
|
|
> More information: <https://learn.microsoft.com/windows-server/administration/windows-commands/for>.
|
2021-12-12 14:29:08 +00:00
|
|
|
|
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
|
|
|
|
2023-02-20 07:23:49 +00:00
|
|
|
`for %{{variable}} in ({{path\to\file1.ext path\to\file2.ext ...}}) do ({{echo Loop is executed}})`
|
2021-12-12 14:29:08 +00:00
|
|
|
|
2021-12-21 12:48:58 +00:00
|
|
|
- Iterate over a given list of directories:
|
2021-12-12 14:29:08 +00:00
|
|
|
|
2023-02-20 07:23:49 +00:00
|
|
|
`for /d %{{variable}} in ({{path\to\directory1.ext path\to\directory2.ext ...}}) do ({{echo Loop is executed}})`
|
2021-12-12 14:29:08 +00:00
|
|
|
|
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}})`
|