0

This is the code I'm using to read and get entries from a zip file:

using (var zip = ZipFile.OpenRead(filePath)) {
    // ... do stuff with zip.Entries
}

I've tried using the ZipArchive constructor as well (which ZipFile.OpenRead is a shortcut to).

Output from the Entries property:

code/views/
code/views/Index.cshtml
config/qa/
config/qa/dist/
config/qa/dist/Web.config

Expected output:

code/
code/views/
code/views/Index.cshtml
config/
config/qa/
config/qa/dist/
config/qa/dist/Web.config

Why are the top-level folders/directories excluded as entries? No other directories are excluded, so this feels like inconsistent behavior to me. Is it a bug in the framework?

Simeon
  • 5,519
  • 3
  • 29
  • 51
  • I'm not sure how the zip format stores directory entries, but maybe it's something weird about the software that created your zip file. Have you tried looking at zips created by other programs? – Joe White Feb 12 '15 at 13:17
  • Seems like those entries are not added by your packing software. Can you post the example .zip file? Does the missing entries break your program? For example, System.IO.Directory.Create creates all missing sub-directories, should work fine. – Dusan Feb 12 '15 at 13:18
  • The ZIP file was created using Explorer.exe in Windows. For my application, I need the listing of hierarchy to work in a consistent way. Regardless of how the ZIP file was created. Otherwise my application will behave inconsistently. So in order to solve that I'll have to create a wrapper to the `ZipArchive` class, it seems, and do this correctly. My questions is whether that's by design (and why). – Simeon Feb 12 '15 at 13:27
  • It is also completely legal (but not so nice) to have only two entries in your case: code/views/Index.cshtml and config/qa/dist/Web.config – Dusan Feb 12 '15 at 13:28
  • The answer is mentioned on [this related post](https://stackoverflow.com/a/40243639/5005279) (with ideas on a work-around). Zip file entries may be directories, but there is no requirement that they be included in the zip file. – Matt Weeden Aug 02 '22 at 20:08

0 Answers0