I would have an automatic way (a local agent) to clean my folders which are empty; the content has been removed by the Expiration Manager.
Subject: Empty folder cleaning
Ok try it. This time, for sure!
Option Public
Option Declare
%INCLUDE “lsconst”
Sub Initialize
On Error Goto sorry
Dim session As New NotesSession
Dim wksp As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim intInd As Integer
Dim docDesignNote As NotesDocument
Dim viewDeletionCandidate List As NotesView ' indexed by folder name
Dim nnc As NotesNoteCollection
Dim strID As String, strTitle As String, strChoices As String, strDeleted As String
Const DIALOGTITLE = "Clean up empty folders"
Const NEWLINE = {
}
Set db = session.CurrentDatabase
Set nnc = db.CreateNoteCollection(False)
nnc.SelectFolders = True
nnc.SelectionFormula = { !@Begins($TITLE; "(") }
nnc.BuildCollection
strID = nnc.GetFirstNoteId
' build a list of folders that need to be updated. We use a Note Collection to get the folders because it's
' a lot faster than iterating thru the db.views array.
Do While strID <> ""
Set docDesignNote = db.GetDocumentByID(strID)
strTitle = Strleft(docDesignNote.GetItemValue("$TITLE")(0) & "|", "|")
Set view = db.GetView(strTitle)
If view.UniversalID <> docDesignNote.UniversalID Then
Msgbox {You have multiple views or folders named "} & strTitle & {". You will need to deal with these manually.}, MB_ICONEXCLAMATION, DIALOGTITLE
Elseif view.EntryCount = 0 Then
Set viewDeletionCandidate(strTitle) = view
strChoices = strChoices & NEWLINE & strTitle
End If
strID = nnc.GetNextNoteId(strID)
Loop
If strChoices = "" Then
Msgbox "It appears you have no empty folders." , 0, DIALOGTITLE
Exit Sub
End If
Dim selection, choices
choices = Split(Mid$(strChoices, 2), NEWLINE)
selection = wksp.Prompt(PROMPT_OKCANCELLISTMULT , DIALOGTITLE, _
"These folders are empty. Deselect any you DO NOT want to delete, and click OK. If you CANCEL, no folders are deleted.", choices, choices)
If Not Isempty(selection) Then
Forall dieFolderDie In selection
Set view = viewDeletionCandidate(dieFolderDie)
Print "Deleting: " & dieFolderDie
strDeleted = strDeleted & NEWLINE & dieFolderDie
Call view.Remove( )
End Forall
End If
If strDeleted = "" Then
Msgbox "No folders were removed.", 0, DIALOGTITLE
Else
Msgbox "Deleted the following folders:" & NEWLINE & strDeleted, 0, DIALOGTITLE
End If
Exit Sub
sorry:
Msgbox "Error " & Err & " on line " & Erl & " of 'Clean up empty folders': " & Error
Exit Sub
End Sub
Subject: RE: Empty folder cleaning
Thanks a lot, it works fine … very useful