If

Top  Previous  Next

 

The If command allows you to specify another Command that should be executed ONLY if a Validation Command (also known as a Condition) executes successfully.

lamp Note: The validation command section of the If command supports the Logical Operators AND '&&' and OR '||' as well as the use of parentheses to construct complex validations based on multiple conditions.

Command Syntax

 

If:[ValidationCondition(s)]:[ValidationConditionParameters],[ExecutableCommand]:[ExecutableCommandParameters],[AlternativeExecutableCommand]:[AlternativeExecutableCommandParameters]

 

The colon after each command and the comma character between Validation and Execution commands are compulsory. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, but parameters may be depending on the operating system and locale.

 

Parameters:

 

ValidiationCondition(s): The validation condition or conditions to evaluate to determine whether or not the ExecutableCommand is executed

ValidationConditionParameters: The parameters required by the ValidationCommand(s). These will be specified in the syntax of the chosen command

ExecutableCommand: The validation command to execute if the ValidationCommand returns true

ExecutableCommandParameters: The parameters required by the ExecutableCommand. These will be specified in the syntax of the chosen command

AlternativeExecutableCommand: The validation command to execute if the ValidationCommand returns false

AlternativeExecutableCommandParameters: The parameters required by the ExecutableCommand. These will be specified in the syntax of the chosen command

 

Validation conditions and Executable commands and their parameters are compulsory and if any of those parameters are missing or invalid an error will be thrown. The AlternativeExecutable command and parameters are optional.

 

This command without the AlternativeExecutable command and parameters acts the same as the If command in most programming languages. With the AlternativeExecutable command and parameters it acts the same as the If...Then...Else construct in most programming languages.

 

In addition you can use the Begin and End commands to create Command Groups. This will allow you to execute multiple commands in the Executable and AlternativeExecutable sections of the command.

 

Examples:

 

This simple example demonstrates using the If command to display a Remark if a specified file exists:

 

If:FileExists:"C:\Test Text.txt",Remark:"The file Exists :-)"

 

This example demonstrates using the If command to create a conditional Copy File command which attempts to copy the specified file ONLY if the FileExists validation command confirms that the file actually exists, otherwise it creates the file:

 

If:FileExists:"C:\Test Text.txt",CopyFile:"C:\Test Text.txt","C:\Test Text (copy).txt",WriteText:"C:\Test Text.txt","This is the new text"

 

This example uses an AND condition to check if two files both exist, and if so write a message to the console and the report. If neither exists, a different message is written.

 

If:FileExists:"C:\MyApp\Test\Test Text.txt"&&FileExists:"C:\Test Text.txt",Remark:"The files are fine :-)",Remark:"The files are most definitely NOT fine :-("

 

This example uses an OR condition to check if either of two files exists, and if at least one of them exists write a message to the console and the report. If neither exists, a different message is written.

 

If:FileExists:"C:\MyApp\Test\Test Text.txt"||FileExists:"C:\Test Text.txt",Remark:"The files are fine :-)",Remark:"The files are most definitely NOT fine :-("

 

See Also: Conditional Commands Conditions Begin End