Extracting a specific folder from a zip using DotNetZip

后端 未结 2 1694
庸人自扰
庸人自扰 2021-01-03 05:11

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\" fr

相关标签:
2条回答
  • 2021-01-03 05:49

    Try this:

    var entries = zip.SelectEntries("*", @"folder1\folder2\");
    foreach (var file in entries)
    {/* extract here */}
    

    I think this is the best approach.

    0 讨论(0)
  • 2021-01-03 05:59

    This worked for me.

              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);        
                        }
                    }
             }
    
    0 讨论(0)
提交回复
热议问题