Tutorial by Examples

SET TEST=0 IF %TEST% == 0 ( echo TEST FAILED ) ELSE IF %TEST% == 1 ( echo TEST PASSED ) ELSE ( echo TEST INVALID )
IF "%~1" == "-help" ( ECHO "Hello" ) where %1 refers to the first command line argument and ~ removes any quotes that were included when the script was called.
If Errorlevel 1 ( Echo Errorlevel is 1 or higher REM The phrase "1 or higher" is used because If Errorlevel 1 statement means: REM If %Errorlevel% GEQ 1 REM Not If %Errorlevel% EQU 1 ) ...
If exist "C:\Foo\Bar.baz" ( Echo File exist ) This checks if the file C:\Foo\Bar.baz's existence. If this exist, it echos File exist The Not operator can also be added.
If Defined Foo ( Echo Foo is defined ) This would check if a variable is defined or not. Again, the Not operator can be used.

Page 1 of 1