Reputation: 230008
ZipeFile file = new ZipFile(filename);
ZipEntry folder = this.file.getEntry("some/path/in/zip/");
if (folder == null || !folder.isDirectory())
throw new Exception();
// now, how do I enumerate the contents of the zipped folder?
Upvotes: 3
Views: 1868
Reputation: 383726
It doesn't look like there's a way to enumerate ZipEntry
under a certain directory.
You'd have to go through all ZipFile.entries()
and filter the ones you want based on the ZipEntry.getName()
and see if it String.startsWith(String prefix)
.
String specificPath = "some/path/in/zip/";
ZipFile zipFile = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry ze = entries.nextElement();
if (ze.getName().startsWith(specificPath)) {
System.out.println(ze);
}
}
Upvotes: 5
Reputation: 6229
You don't - at least, not directly. ZIP files are not actually hierarchical. Enumerate all the entries (via ZipFile.entries() or ZipInputStream.getNextEntry()) and determine which are within the folder you want by examining the name.
Upvotes: 1