IBM Support

Using the Dir function in recursive LotusScript

Technote (FAQ)


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 Initialize
      ScanDirs("c:\Test Folder")
    End Sub

    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 = "/"
      End If
        Redim DirList(0)
        If Instr(path, sep) > 0 Then
          filepath = Strleftback(path, sep)
        End If
          filename = Dir(path, 16)
          While filename <> ""
            If filename <> "." And filename <> ".." Then
              If (GetFileAttr(filepath & sep & filename) And 16) >0 Then
        DirList = Arrayappend(DirList,filepath & sep & filename & sep)
                    ' ON filepath & sep & filename
                    ' OR filename (as desired)
              End If
            End If
              filename = Dir
            DirList = Fulltrim(DirList)
              Forall dirpath In DirList
              End Forall
        End If
      End Sub

Cross reference information
Segment Product Component Platform Version Edition
Messaging Applications IBM Notes Linux, Mac OS, Windows 8.0, 7.0, 6.5, 6.0, 5.0 All Editions

Document information

More support for: IBM Domino Designer

Software version: 6.0, 6.5, 7.0, 8.0, 8.5

Operating system(s): Windows

Reference #: 1317698

Modified date: 08 September 2008

Translate this page: