Independentsoft
Home
Purchase
Support
Company
Contact
JPST
>
Tutorial
> List all folders
The following example shows you how recursively get and list all folders.
import java.io.IOException; import java.util.Hashtable; import java.util.List; import com.independentsoft.pst.Folder; import com.independentsoft.pst.PstFile; public class Example { public static void main(String[] args) { try { PstFile file = new PstFile("c:\\testfolder\\Outlook.pst"); try { Folder startFolder = file.getMailboxRoot(); List
folders = startFolder.getFolders(true); String parentFolder = startFolder.getDisplayName(); Hashtable
parents = new Hashtable
(); parents.put(startFolder.getId(), parentFolder); for (int i = 0; i < folders.size(); i++) { Folder currentFolder = folders.get(i); parentFolder = parents.get(currentFolder.getParentId()); String currentFolderPath = parentFolder + "\\" + currentFolder.getDisplayName(); parents.put(currentFolder.getId(), currentFolderPath); System.out.println("Id: " + currentFolder.getId()); System.out.println("Name: " + currentFolder.getDisplayName()); System.out.println("Type: " + currentFolder.getContainerClass()); System.out.println("Item count: " + currentFolder.getItemCount()); System.out.println("Path: " + currentFolderPath); System.out.println("--------------------------------------------------------"); } } finally { if (file != null) { file.close(); } } } catch (IOException e) { e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*