Ionic Zip 仅提取特定文件夹

Das*_*han 3 c# zip unzip

我有一个案例,我需要使用 C# Ionic.zip 库提取 Zip 文件。Zip 文件包含多个文件夹,我想提取特定文件夹并将其复制到特定目的地。

例如,名为 abc.zip 的 Zip 文件和目录结构如下

父目录->子目录1->文件a、文件b 父目录->子目录2->文件c、文件d

我只想复制子目录1,我该如何完成这个任务?

pla*_*ful 5

        var existingZipFile = "name of the file.zip";
        var targetDirectory = "name of the folder";

        using (ZipFile zip = ZipFile.Read(existingZipFile))
        {
            foreach (ZipEntry e in zip.Where(x => x.FileName.StartsWith("Sub directory 1")))
            {
                e.Extract(targetDirectory);
            }
        }
Run Code Online (Sandbox Code Playgroud)