使用DotNetZip从zip提取特定文件夹 [英] Extracting a specific folder from a zip using DotNetZip

查看:272
本文介绍了使用DotNetZip从zip提取特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一些示例,但是似乎找不到涉及提取特定文件夹的DotNetZip方案.我正在尝试从.zip文件中提取一个名为"CSS"的文件夹,它是.zip文件中的顶级文件夹.这是我到目前为止的代码:

I've searched around for examples, but can't seem to find a DotNetZip scenario that involves extracting a certain folder. I'm trying to extract a folder called "CSS" from a .zip file, and it is a top-level folder inside the .zip file. This is the code I have so far:

using (ZipFile zip1 = ZipFile.Read(savedFileName))
{
    var selection = from e in zip1.Entries
                    where System.IO.Path.GetFileName(e.FileName).StartsWith("CSS/")
                    select e;

    foreach (var e in selection)
    e.Extract(_contentFolder);                
}

当前选择内容没有任何帮助,我可以使用一些帮助来重写它,以便提取css文件夹及其所有子目录和文件.

The current selection grabs nothing, and I could use some help rewriting it so it extracts the css folder and all of its subdirectories and files.

推荐答案

这对我有用.

          public void ExtractFiles(string fileName, string outputDirectory)
          {
                using (ZipFile zip1 = ZipFile.Read(fileName))
                {
                    var selection = (from e in zip1.Entries
                                     where (e.FileName).StartsWith("CSS/")
                                     select e);


                    Directory.CreateDirectory(outputDirectory);

                    foreach (var e in selection)
                    {                            
                        e.Extract(outputDirectory);        
                    }
                }
         }

这篇关于使用DotNetZip从zip提取特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆