How to list archive folders

Listing archive folders

GroupDocs.Viewer provides additional information such as list of folders when calling getViewInfo(…) method. To retrieve view information for Archive File call getViewInfo(…) method and cast output result to ArchiveViewInfo type.

Following example demonstrates how to print out archive contents.

    public void printViewInfo() {
        try (Viewer viewer = new Viewer("")) {
            ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();
            ViewInfo viewInfo = viewer.getViewInfo(viewInfoOptions);
            System.out.println("File type: " + viewInfo.getFileType());
            System.out.println("Pages count: " + viewInfo.getPages().size());
            System.out.println("Folders: ");
            System.out.println(" - /");
            String rootFolder = StringExtensions.Empty;
            printFolders(viewer, rootFolder);

    private void printFolders(Viewer viewer, String folder) {
        ViewInfoOptions viewInfoOptions = ViewInfoOptions.forHtmlView();

        ArchiveViewInfo viewInfo = (ArchiveViewInfo) viewer.getViewInfo(viewInfoOptions);

        for (String subFolder : viewInfo.getFolders()) {
            System.out.println(" - " + subFolder);
            printFolders(viewer, subFolder);

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.