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