我的问题很简单,我有一个 zip 文件,其中包含很多文件(混合:pdf png 和 txt)。我需要编写一个 C# 程序来查看 zip 文件、循环并仅打开 png 文件而不解压缩。我找到的所有解决方案都包括解压缩整个 zip 文件,这只会使目标文件夹更重。 最简单的方法是什么?
非常感谢,
乔什。
最佳答案
我相信您可以使用 System.IO.Compression 库...
程序集:System.IO.Compression.ZipFile.dll
类似下面的内容...
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(destinationPath);
}
}
}
关于c# - 有没有办法在不解压的情况下打开zip文件中的文件(c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65810663/