2021-12-11 04:30:29 +00:00
|
|
|
# if
|
|
|
|
|
|
|
|
> Performs conditional processing in batch scripts.
|
2022-10-04 16:06:23 +01:00
|
|
|
> More information: <https://learn.microsoft.com/windows-server/administration/windows-commands/if>.
|
2021-12-11 04:30:29 +00:00
|
|
|
|
|
|
|
- Execute the specified commands if the condition is true:
|
|
|
|
|
|
|
|
`if {{condition}} ({{echo Condition is true}})`
|
|
|
|
|
|
|
|
- Execute the specified commands if the condition is false:
|
|
|
|
|
|
|
|
`if not {{condition}} ({{echo Condition is true}})`
|
|
|
|
|
|
|
|
- Execute the first specified commands if the condition is true otherwise execute the second specified commands:
|
|
|
|
|
|
|
|
`if {{condition}} ({{echo Condition is true}}) else ({{echo Condition is false}})`
|
|
|
|
|
|
|
|
- Check whether `%errorlevel%` is greater than or equal to the specified exit code:
|
|
|
|
|
2023-02-20 07:23:49 +00:00
|
|
|
`if errorlevel {{2}} ({{echo Condition is true}})`
|
2021-12-11 04:30:29 +00:00
|
|
|
|
|
|
|
- Check whether two strings are equal:
|
|
|
|
|
2022-01-30 01:58:41 +00:00
|
|
|
`if %{{variable}}% == {{string}} ({{echo Condition is true}})`
|
2021-12-11 04:30:29 +00:00
|
|
|
|
|
|
|
- Check whether two strings are equal without respecting letter case:
|
|
|
|
|
2022-01-30 01:58:41 +00:00
|
|
|
`if /i %{{variable}}% == {{string}} ({{echo Condition is true}})`
|
2021-12-11 04:30:29 +00:00
|
|
|
|
|
|
|
- Check whether a file exist:
|
|
|
|
|
2023-02-20 07:23:49 +00:00
|
|
|
`if exist {{path\to\file}} ({{echo Condition is true}})`
|