Enumerate Folders
Enumerates the folder hierarchy of a PST file.
Code
using DRIT.Mail.Pst.PhysicalLayout;
using var pst = new PstFile("archive.pst");
void PrintFolders(Folder folder, int depth)
{
string indent = new string(' ', depth * 2);
Console.WriteLine($"{indent}{folder.Name} ({folder.MessageCount} messages)");
foreach (var child in folder.SubFolders)
{
PrintFolders(child, depth + 1);
}
}
PrintFolders(pst.Folders.Root, 0);
Remarks
The folder hierarchy is rooted at pst.Folders.Root. Use
GetAllFoldersFlatDepthFirst() to iterate all folders without recursion.