Reg Exp
Web Design
Notes Client
Removing Empty Folders From Your Mail
A few weeks ago someone asked about removing empty folders from their mail. They were archiving stuff and the archive didn't remove the empty folders, so their mail file had a bunch of empty folders lying around. Here is code that can be placed in a button. The button goes through all the folders in the current database (which is assumed to be their mail file because the button was sent to them). If an empty folder is found, they are prompted whether it should be deleted or not. If the user says "Yes", then the folder is marked for deletion (not immediately deleted). After all the folders are investigated, the ones that were marked for deletion are deleted from the database. All throughout the process messages are printed to the status bar.

Sub Click(Source As Button)
   Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim viewNames() As String
   Dim count As Integer
   Dim firstDoc As NotesDocument
   Dim results As String
   Dim answer As Integer
   Dim designDoc As NotesDocument
   Dim view As NotesView
   Dim user As String
   Dim foundAny As Integer
   Print "Initializing..."
   user = session.UserName
   Set db = session.CurrentDatabase
   count = 0
   foundAny = False
   Forall indView In db.Views
      If indView.IsFolder Then
         Set designDoc = db.GetDocumentByUNID(indView.UniversalID)
         If designDoc.Signer = user Then ' Ignore system folders like ($Inbox)
            Print "Checking " & indView.Name & "..."
            Call indView.Refresh ' Make sure we have the latest index
            Set firstDoc = indView.GetFirstDocument
            If firstDoc Is Nothing Then
               foundAny = True
               results = "The folder " & indView.Name & " is empty. Would you like to delete it?"
               answer = Msgbox(results, 64+3, "Results")
               If answer = 2 Then Exit Sub ' User clicked cancel
               If answer = 6 Then ' User clicked Yes
                  Redim Preserve viewNames(count)
                  viewNames(count) = indView.Name
                  count = count + 1
               End If
            End If
            Print indView.Name & " is a system folder... Skipping..."
         End If
         Print indView.Name & " is not a folder... Skipping..."
      End If
   End Forall
   Print " " ' Clear the status bar
   If Not foundAny Then ' No empty folders were found
      Msgbox "No empty folders were found in " & db.Title & ".", 64, "Results"
      Exit Sub
   End If
   If count = 0 Then Exit Sub ' No empty folders marked for deletion
   For count = 0 To Ubound(viewNames)
      Print "Deleting folder " & viewNames(count) & "..."
      Set view = db.GetView(viewNames(count))
      If Not view Is Nothing Then Call view.Remove
   Print " "
End Sub