|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > Filesystem-Commands |
MiniRobotLanguage (MRL)
IFI. / NFI. Conditional Statement
If Is File (Not Is File)
Intention
Conditional Statement. Tests if a specified path exists and determines if it is a file (1), a directory (2), or does not exist (0).
Returns the result on the Top Of Stack (TOS) and executes the corresponding code block based on the condition.
' Check if a path is a file
IFI.?desktop\test.txt
PRT.Path is a file: $tos$
ELS.
PRT.Path is not a file or does not exist: $tos$
EIF.
You can use NFI. (Not Is File) as the negative form of the command.
Syntax
IFI.P1 … ELS. … EIF.
NFI.P1 … ELS. … EIF.
Parameter Explanation
P1 - Variable/filename/directory-path
Return Values
These values are on TOS after calling the command.
0 - Path does not exist
1 - Path is a file
2 - Path is a directory
Example
'**********************************************
' IFI-Sample
'**********************************************
IFI.?desktop\test.txt
PRT.Result: $tos$ - File exists
ELS.
PRT.Result: $tos$ - Not a file or doesn't exist
EIF.
' Check a directory
NFI.?ws\
PRT.Result: $tos$ - Is not a file (might be a dir)
ELS.
PRT.Result: $tos$ - Is a file
EIF.
END.
Remarks
IFI. and NFI. can be nested to unlimited depth and can enclose sub-program calls.
Limitations:
Does not support wildcards in the path specification.
See also:
IDI. / NDI. - If Is DIrectory