Using the Dir function in recursive LotusScript
In Lotus Domino®, the LotusScript language includes the Dir function which allows you to navigate the file system building a list of files in a directory. As described in the Domino Designer Online Help, it is not designed to be used recursively. What does this mean and can you actually write recursive code that uses the Dir function?
Recursive use of a function or subroutine is where the function or subroutine either calls itself, typically when the output from a call to the function or subroutine is used as a parameter in an additional call (to the function or subroutine). The Dir function may not be called recursively; it does not save a history of the calls made to it. The Domino Designer Online Help entry for the function includes the following in the Usage section: "The Dir or Dir$ function may not be called recursively."
NOTE: Attempting to use the Dir function recursively will by design produce an "Illegal function call: error.
NOTE: The code examples below are sample scripts, provided to illustrate one way to approach this issue. In order for the examples to perform as intended, they must be laid out exactly as indicated below. Lotus Support cannot customize the scripts for specific environments or applications.
In this example, a subroutine is called recursively to work around the issue. A check is done using GetFileAttr and the directory path is stored in an array. Once the Dir function finishes scanning the directory, it loops through the array using ForAll and calls the ScanDirs subroutine recursively and safely.
Sub ScanDirs(path As String)
Dim sess as New NotesSession
Dim DirList As Variant
Dim filename As String
Dim filepath As String
Dim sep As String
If path <> "" Then
If Instr(sess.Platform, "Windows") > 0 Then
sep = "\"
sep = "/"
If Instr(path, sep) > 0 Then
filepath = Strleftback(path, sep)
filename = Dir(path, 16)
While filename <> ""
If filename <> "." And filename <> ".." Then
If (GetFileAttr(filepath & sep & filename) And 16) >0 Then
' PERFORM DESIRED CHECK/OPERATION
' ON filepath & sep & filename
' OR filename (as desired)
filename = Dir
DirList = Fulltrim(DirList)
Forall dirpath In DirList
|Messaging Applications||IBM Notes||Linux, Mac OS, Windows||8.0, 7.0, 6.5, 6.0, 5.0||All Editions|
Translate this page: