Is your Outlook mailbox overflowing? TreeMap it!

In this post I published 100 lines of code that showed how to get a visual representation of your hard disk to see which folders take the most space. It showed that my Outlook mailbox was half a gigabyte. (“C:\DOCUMENTS AND SETTINGS\CALVINH\LOCAL SETTINGS\APPLICATION DATA\MICROSOFT\OUTLOOK” ). I am using some great features of Outlook: Cached Exchange Mode which makes my entire mailbox available offline and RPC over HTTP which allows me to use Outlook over an internet connection without logging onto the network at work. I just knew cached mode used a lot of space!

Well it was really simple to add another method onto the class to map my Outlook Mailbox visually to see what was taking the most space within that half gigabyte. The rest of the code just works as expected: Tooltips show the folder name and size, and you can click on a rectangle to drill down into the tree.

As an exercise, you could even modify the code so that if you navigate through your hard disk folders to the Outlook folder on your hard disk, it seamlessly just drills down into your mailbox inside.


Use this line to create the form. Here, I’m using “*” to represent an Outlook 2003 mailbox. Be sure to change the mailbox name. Note it uses GETOBJECT function which assumes Outlook is already running.




In the INIT method, Replace the this.DoDir(cPath) line with


                  IF cPath=”*”

                        loApp = GETOBJECT(“”,”Outlook.application”)


                        oFolder=oSpace.Folders(“MailBox – Calvin Hsia“)







And then add this method


      PROCEDURE DoOutlook(cPath as String, nDepth as Integer, oFolder as Outlook.MAPIFolder) as Number   && Recursive routine to get folders and their sizes

            LOCAL oSubfolder as Outlook.MAPIFolder,oItem as Outlook.MailItem

            LOCAL nTotal, nFileTotal




            FOR EACH oSubfolder as Outlook.MAPIFolder IN oFolder.Folders



            FOR EACH oItem as Outlook.MailItem IN oFolder.Items






            nTotal= nTotal+nFileTotal

            INSERT INTO dirs (Path,Depth,size) VALUES (cPath+’\’,nDepth,nTotal)     && insert the total subfolder info

            IF nFileTotal>0

                  INSERT INTO dirs (Path,Depth,size) VALUES (cPath+”*\”,nDepth+1,nFileTotal)      && for items within current folder


      RETURN nTotal




Comments (2)

  1. I received an email forwarded from my wife with my daughter’s soccer schedule. Of course it had been…

    1. Ron Radke says:

      June 23, 2016
      Hi Calvin
      I’ve got some compiled/code written for 286’s on 5 &1/4 floppies that I’d like to convert to ?.
      1. Program to read old
      2. Translate into machine readable
      3. Convert to Fortran
      4. Compile & Run in Fortran and/or FoxPro
      Ronald Radke
      Michigan Public Service Commission
      517 284 8279

Skip to main content