List 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("sample.zip")) {
            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();
        viewInfoOptions.getArchiveOptions().setFolder(folder);

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

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