Name
if
Synopsis
Execute a command if certain conditions are met.
Syntax
if [not]string1==string2command[arguments] if [/i]string1 compare-op string2command[arguments] if [/i]string1 compare-op string2command[arguments] if [not] existfilenamecommand[arguments] if [/i]string1 compare-op string2command[arguments] if [not] existfilenamecommand[arguments] if [not] errorlevelncommand[arguments]
Description
Conditional branching lets your batch file test to see whether a
condition is true, and if it is, instructs the batch file to execute
a command or continue execution at another location in the batch file
(via the goto command). The following options can
be used with the if command:
-
command[arguments] The command to execute or the program filename to run. This can be anything you’d normally type at a command prompt;
argumentsare the options, if any, to pass to the command.-
not Specifies that
commandshould be carried out only if the condition is false; not valid withcompare-op.-
string1==string2 Specifies a true condition if the specified text strings match.
String1andstring2must be enclosed in quotation marks or parenthesis.-
string1compare-opstring2 Performs a more flexible comparison than
string1==string2, shown above. Thecompare-opterm can be one of the following:-
EQU Equal
-
NEQ Not equal
-
LSS Less than
-
LEQ Less than or equal
-
GTR Greater than
-
GEQ Greater than or equal
-
- /i
Specifies a case-insensitive comparison; used only with
compare-op.-
existfilename ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access