How to get folder size of a pst




I need to have the folder size of a personal folder (pst)

I've already implemented a simple (but slow) solution, may there is a better
function already included in the outlook objects ?
How does it works on "properties" -> "folder size" ? It seams to be faster.

Public Sub FolderCleanUp()

Dim FolderSize As Long

Dim myOlApp As Outlook.Application 'Outlook-Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")

'Scan all folders
For Each myFolder In myNameSpace.Folders

'Determine Size of all elements in this folder incl. sub-folders
FolderSize = DetermineSize(myFolder)

Debug.Print (myFolder.Name & vbCrLf & _
" " & ShowSize(FolderSize))

Next myFolder

End Sub

' Rekursive Funktion zur Bestimmung der Größe aller Objekte in einem Ordner
(inkl. Unterordner)
Private Function DetermineSize(objFolder As MAPIFolder) As Long

Dim i As Long
DetermineSize = 0

'Die Größe der Objekte im Ordner addieren (Items)
For i = 1 To objFolder.Items.Count
DetermineSize = DetermineSize + objFolder.Items.Item(i).Size
Next i

'Die Unterordner nun auch noch durchsuchen (Folder)
For i = 1 To objFolder.Folders.Count
DetermineSize = DetermineSize + DetermineSize(objFolder.Folders.Item(i))
Next i

End Function



Ken Slovak - [MVP - Outlook]

That's about it. You can probably add about 10% to your calculations for
hidden items, overhead data, etc.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question