質問

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