DotNetZip.Semverd icon indicating copy to clipboard operation
DotNetZip.Semverd copied to clipboard

Folders

Open timhargan opened this issue 9 years ago • 2 comments

When I am adding files using a stream and I want to create a folder structure of files this way there is a problem with the folders. It will create the paths in the zip file for the files but I cant get it to actually create the folder entries in the zip. How can I create the folder entry without the file system? This is an issue with opening this with other systems.

timhargan avatar Jan 28 '17 01:01 timhargan

ZipFile contains a method for that.

ZipEntry zd = zf.AddDirectoryByName(folder.Path);

Then zd will allow you to set folder parameters like time and so on. When saved it will contain the folder entries in the ZIP file as expected.

claunia avatar May 16 '17 05:05 claunia

I know this is old but I couldn't find this info anywhere else. If you append a DirectorySeperatorChar to the filename it will create it as an empty directory entry.

...
using (var zip = new ZipOutputStream(fileStream))
{
     if (!directoryName.EndsWith(Path.DirectorySeparatorChar.ToString()))
          directoryName += Path.DirectorySeparatorChar.ToString();

     var entry = zip.PutNextEntry(directoryName);
}
...

This issue can be closed.

msoler8785 avatar May 30 '18 21:05 msoler8785