Ask the Expert

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.

This was first published in October 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: