Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract a ZIP file programmatically by DotNetZip library?

I have a function that get a ZIP file and extract it to a directory (I use DotNetZip library.)

public void ExtractFileToDirectory(string zipFileName, string outputDirectory) {      ZipFile zip = ZipFile.Read(zipFileName);      Directory.CreateDirectory(outputDirectory);      zip.ExtractAll(outputDirectory,ExtractExistingFileAction.OverwriteSilently); } 

My ZIP file contains multiple files and directories. But I want to extract only some of these files, not all of them.

How can I make this work?

like image 978
Ehsan Avatar asked Feb 24 '10 08:02

Ehsan


People also ask

How do I extract a ZIP file in Python?

Python3. # into a specific location. Import the zipfile module Create a zip file object using ZipFile class. Call the extract() method on the zip file object and pass the name of the file to be extracted and the path where the file needed to be extracted and Extracting the specific file present in the zip.


1 Answers

You need to test each ZipEntry to see if you want to extract it:

public void ExtractFileToDirectory(string zipFileName, string outputDirectory) {      ZipFile zip = ZipFile.Read(zipFileName);      Directory.CreateDirectory(outputDirectory);       foreach (ZipEntry e in zip)       {         // check if you want to extract e or not         if(e.FileName == "TheFileToExtract")            e.Extract(outputDirectory, ExtractExistingFileAction.OverwriteSilently);       } } 
like image 110
Oded Avatar answered Oct 05 '22 18:10

Oded