[英]C# Get top level files from zip file only
I am trying to get all the file names that are located in the top level of a zip file and not anything in subdirectories.我试图获取位于 zip 文件顶层的所有文件名,而不是子目录中的任何文件名。
The code I'm currently using is我目前使用的代码是
using System.IO.Compression.ZipFile;
using (var zip = ZipFile.OpenRead(pathToZip))
{
foreach (var e in zip.Entries)
{
var filename = e.Name;
}
}
But this code gets all the files in the zip.但是这段代码获取了 zip 中的所有文件。 Any help is much apricated.任何帮助都非常有用。
Thanks谢谢
This code will extract only files that are not contained in a directory:此代码将仅提取目录中不包含的文件:
using (var zip = ZipFile.OpenRead(pathToZip))
{
foreach (var e in zip.Entries.Where(e => !e.FullName.Contains("/")))
{
{
var filename = e.Name;
Console.WriteLine(filename);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.