Problem solve Get help with specific problems with your technologies, process and projects.

How can I get a list of folders available on the server?

Two questions:

  1. How can I get a list of folders available on the server?

  2. If I want to access a list of databases in a particular folder, can I/how do I get a handle on only these databases if I know the folder name?

You can get a list of all the folders in a particular directory of the server using the Dir$ function in LotusScript. However, this code would have to run on the server –- not from a workstation. And the server agent must run with unrestricted access. You can run a server agent from the workstation using the NotesAgent.RunOnServer method. This article shows how to do that.

Dir$ can also locate all the .nsf files in a folder. But, Notes provides another way to do that, the NotesDBDirectory class. There's no way to tell the class to restrict itself to databases in a specific folder. But, it's very fast if all you do is look at the database filepaths. You don't have to "Open" the NotesDatabase object to read the Filepath property. So you can very quickly iterate through all the databases and skip the ones that don't start with the right path. Other advantages of NotesDbDirectory are: it will work in code run from a workstation and does not require unrestricted access.

Function AllDBsInFolder(Byval 
strServer As String, Byval 
strFolder As String, 
Byval intFileType As Integer) As Variant 
        On Error Goto oops 
        Redim result(0 To 100) As 
        Dim intCount As Integer 
        Dim dbdir As New 
        Dim db As NotesDatabase 
        If Right$(strFolder, 1) <> 
"" Then strFolder = strFolder & "" 
        Set db = dbdir.
        Do Until db Is Nothing 
                If Left$(db.FilePath , 
Len(strFolder)) = strFolder Then 
                        If intCount > 
Ubound(result) Then 
Preserve result(0 To intCount + 100) 
                        End If 
                        Set result(intCount) = db 
                        intCount = intCount + 1 
                End If 
                Set db = 
dbdir.GetNextDatabase( ) 
        If intCount > 0 Then 
                If intCount >= 
Ubound(result) Then 
                        Redim Preserve 
result(0 To intCount - 1) 
                End If 
                AllDBsInFolder = result 
        End If 
        Exit Function 
        Error Err , Error & 
"//AllDBsInFolder:" & Erl 
End Function 

. . . 
Dim matches As Variant 
matches = AllDBsInFolder
("Rex/Yoyodyne", "mail", DATABASE) 
If Not IsEmpty(matches) Then 
        Forall db In matches 
                ' process one database here. 

Do you have comments on this Ask the Expert question and response? Let us know.

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...