有没有办法确定.net 4.5 ZipArchive是否包含具有指定名称的空文件夹?
据我所知,只有一组条目会忽略空文件夹。
答案 0 :(得分:2)
我没有忽略空文件夹的问题,以下内容适用于我:
string zipPath = @"C:\test.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
/* Find all folders (elements ending with "/"), and exclude
* those containing elements (FullName starts with folder name, FullName is
* longer than folder name) */
var entries = archive.Entries.Where(o1 => o1.FullName.EndsWith("/")
&& !archive.Entries
.Any(o2 => o2.FullName.StartsWith(o1.FullName)
&& o2.FullName.Length > o1.FullName.Length)).ToList<ZipArchiveEntry>();
}