If Command In Windows Server 2008
In this article I am going to explain about IF Command in Windows Server 2008 operating system and also explain it's related syntax.
Introduction
If command applies to all versions of Windows. If command conditionally performs a command in batch program. If the condition is true then the command specified in if clause is carried out. If the condition is false then the command specified in else clause is carried out and command in the if clause is ignored.
Syntax
if [not] ERRORLEVEL <Number> <Command> [else <Expression>]
if [not] <String1>==<String2> <Command> [else <Expression>]
if [not] exist <FileName> <Command> [else <Expression>]
|
Error check syntax
if [/i] <String1> <CompareOp> <String2> <Command> [else <Expression>]
if cmdextversion <Number> <Command> [else <Expression>]
if defined <Variable> <Command> [else <Expression>]
|
Parameter |
Description |
<Command> |
The command to perform if the condition is met. |
not |
Perform the command, only if the condition is false. |
ERRORLEVEL <Number> |
Specifies condition will be true only if last program run by command shell returned an exit code >= number. |
<String1>==<String2> |
Performs the command only if String1 and String2 are the same. |
exist <FileName> |
True condition if the given file name exists. |
<CompareOp> |
May be one of: following three letter comparison operator:
EQU Equal to
NEQ Not equal
LSS : Less than <
LEQ Less than or equal to
GTR Greater than >
GEQ Greater than or equal to |
/i |
Forces string comparisons to ignore case. |
cmdextversion <Number> |
True condition only if the internal version number associated with the command extensions feature is >= number.. |
defined <Variable> |
Denotes a true condition if variable is defined. |
<Expression> |
The command to perform specified in else clause. |
Example
IF EXIST C:\department (echo complete) ELSE (echo failed)
|
OUTPUT:
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here