Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i add a whole folder to a zip archive

Tags:

c#

dotnetzip

I tried the zip.AddDirectory thing, but I can't figure out how to import a whole folder to an archive(Using DotNetZip).

I do NOT want this:

enter image description here

But this:

enter image description here

like image 567
user2001305 Avatar asked Dec 09 '25 20:12

user2001305


1 Answers

From the DotNetZip source code examples :

Remap directories. Zip up a set of files and directories, and re-map them into a different directory hierarchy in the zip file:

using (ZipFile zip = new ZipFile())
{
    // files in the filesystem like MyDocuments\ProjectX\File1.txt , will be stored in the zip archive as  backup\File1.txt
    zip.AddDirectory(@"MyDocuments\ProjectX", "backup");
    // files in the filesystem like MyMusic\Santana\OyeComoVa.mp3, will be stored in the zip archive as  tunes\Santana\OyeComoVa.mp3
    zip.AddDirectory("MyMusic", "tunes");
    // The Readme.txt file in the filesystem will be stored in the zip archive as documents\Readme.txt
    zip.AddDirectory("Readme.txt", "documents");
    zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G") ; 
    zip.Save(ZipFileToCreate);
}
like image 193
Chris Avatar answered Dec 12 '25 08:12

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!