如何在 c# 中列出 .zip 文件夹的内容? [英] How can I list the contents of a .zip folder in c#?
问题描述
如何在 C# 中列出压缩文件夹的内容?例如,如何知道一个压缩文件夹中包含多少个项目,它们的名称是什么?
How can I list the contents of a zipped folder in C#? For example how to know how many items are contained within a zipped folder, and what is their name?
推荐答案
.NET 4.5 或更新版本终于具有内置功能,可以使用 System.IO.Compression.ZipArchive
类处理通用 zip 文件(http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx) 在汇编 System.IO.Compression 中.不需要任何第三方库.
.NET 4.5 or newer finally has built-in capability to handle generic zip files with the System.IO.Compression.ZipArchive
class (http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive%28v=vs.110%29.aspx) in assembly System.IO.Compression. No need for any 3rd party library.
string zipPath = @"c:examplestart.zip";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
Console.WriteLine(entry.FullName);
}
}
这篇关于如何在 c# 中列出 .zip 文件夹的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!