Question

I'm trying to use DotNetZip to create a zip file in C#.NET. However, I do need to include empty folders from time to time. Is this possible? Are there any tricks to make it happen?

Était-ce utile?

La solution

There is an AddDirectory function:

zipFile.AddDirectory("\\Your\Directory\Path\");

I believe the empty directory must already exist at the location you are zipping from, so you may need to first create the empty directory on the server. Here are some examples.

Autres conseils

McCee's solution didn't quite work for me. This however did:

First we get all the empty directories in the path of files to zip. Then we use AddDirectoryByName to append it to the zip object, i.e.

foreach (var folder in Directory.GetDirectories(pathOfFilesToZip).Where(x => !Directory.EnumerateFileSystemEntries(x).Any()))
{
    zip.AddDirectoryByName(Path.GetFileName(folder));
}       
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top