0 votes
by (8.5k points)
edited by

Is there an option to exclude the root folder from the archive when creating a zip from a directory? Sometimes you want only the folder content, not the actual folder itself.

Applies to: Rebex ZIP

1 Answer

0 votes
by (58.9k points)
selected by
 
Best answer

Yes, zipping all content from a specified directory is possible in C# with Rebex ZIP as it supports wildcards.

There are 2 ways to do it, either specify the content of the directory with the "*" mask like this:

ZipArchive zip = new ZipArchive("archive.zip");

//add the content of the "C:\MyData" directory (the "C:\MyData" directory itself will not be added to the archive).
zip.Add(@"C:\MyData\*");

zip.Close();

or use the FileSet class in combination with the "*" pattern to match the content of the directory like this:

ZipArchive zip = new ZipArchive("archive.zip");

// or aternatively use FileSet class to specify all content of the C:\MyData folder:
var fileSet = new FileSet(@"C:\MyData\", "*");
zip.Add(fileSet);

zip.Close();
...