Extract a specific folder from zip using DotNetZip

I searched for examples, but cannot find a DotNetZip script that involves extracting a specific folder. I am trying to extract a folder called "CSS" from a .zip file, and this is the top level folder inside the .zip file. This is the code that I still have:

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); } 

The current selection doesn't capture anything, and I can use some help by rewriting it so that it extracts the css folder and all its subdirectories and files.

+4
source share
2 answers

It 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); } } } 
+8
source

Try the following:

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

I think this is the best approach.

+2
source

Source: https://habr.com/ru/post/1336883/


All Articles