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?

有帮助吗?

解决方案

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.

其他提示

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));
}       
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top