سؤال

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