Extract Subfiles
To access all files in a container file, the container must be opened and its subfiles extracted to either a file or a stream. The extraction process is done repeatedly until all subfiles are extracted and exposed for
If you want to filter a container file and its subfiles, to a single file, you must extract all files from the container, filter the files, and then append the filtered text to the same output file.
You can iterate over subfile information by calling the subfiles method on a document object. Each element returned by the iterator contains information about the subfile, and a method to let you extract it:
for (Subfile subfile : myDoc.subfiles()) {
System.out.println("Subfile " + subfile.index() + ", size: " + subfile.size());
if (subfile.type() != keyview.filter.SubfileType.Folder) {
subfile.extractToFile(generateOutputPath(subfile));
}
}
In this example, generateOutputPath() is a function that returns the path you want to use for the extracted subfile. If the name of the subfile does not matter (for example, the subfile will being passed into File Content Extraction for further processing) you could use a unique identifier like a GUID. If you instead choose to base the filename on subfile.rawName() - the path the container file provides - you should ensure you protect against directory traversal attacks (where the name of the subfile contains a relative or absolute path).