Csharp/C#教程:如何从C#.NET 4.5中的zip存档中提取特定目录?分享


如何从C#.NET 4.5中的zip存档中提取特定目录?

我有以下内部结构的zip文件:

file1.txt directoryABC fileA.txt fileB.txt fileC.txt 

将文件从“directoryABC”文件夹中提取到硬盘上的目标位置的最佳方法是什么? 例如,如果目标位置是“C: temp”,那么其内容应为:

 temp directoryABC fileA.txt fileB.txt fileC.txt 

此外,在某些情况下,我只想提取“directoryABC”的内容,结果将是:

 temp fileA.txt fileB.txt fileC.txt 

如何通过在C#.NET 4.5中使用System.IO.Compression中的类来实现此目的?

这是另一个将命名目录的文件解压缩到目标目录的版本……

上述就是C#学习教程:如何从C#.NET 4.5中的zip存档中提取特定目录?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 class Program { static object lockObj = new object(); static void Main(string[] args) { string zipPath = @"C:TempTestTest.zip"; string extractPath = @"c:Tempxxx"; string directory = "testabc"; using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { var result = from currEntry in archive.Entries where Path.GetDirectoryName(currEntry.FullName) == directory where !String.IsNullOrEmpty(currEntry.Name) select currEntry; foreach (ZipArchiveEntry entry in result) { entry.ExtractToFile(Path.Combine(extractPath, entry.Name)); } } } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/962252.html

(0)
上一篇 2021年11月26日
下一篇 2021年11月26日

精彩推荐