简体   繁体   中英

Missing root directory entries when extracting using ZipArchive in .NET 4.5

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?

The answer is mentioned on this related post (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM