I want to be able creating zip files that contain empty folders, using ICSharpCode.SharpZipLib.Zip.ZipOutputStream
. I can use ICSharpCode.SharpZipLib.Zip.FastZip.CreateEmptyDirectories = true
, but FastZip doesn't allow UTF8 file names.
Asked
Active
Viewed 1,784 times
1
2 Answers
1
I know this is very old but I came across the same issue (zipping empty directories with ZipOutputStream).
I am making a recursive call based on different parent directories.
public void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset)
{
var files = Directory.GetFiles(path);
var directories = Directory.GetDirectories(path);
//this is where I add the empty directory
//code begin
if (files.Count() == 0 && directories.Count() == 0)
{
DirectoryInfo di = new DirectoryInfo(path);
string cleanName = ZipEntry.CleanName(path.Substring(folderOffset)) + "/";
ZipEntry zipEntry = new ZipEntry(cleanName);
zipEntry.DateTime = di.LastWriteTime;
zipStream.PutNextEntry(zipEntry);
zipStream.CloseEntry();
return;
}
//code end
foreach (string file in files)
{
FileInfo fileInfo = new FileInfo(file);
string cleanName = ZipEntry.CleanName(file.Substring(folderOffset));
ZipEntry zipEntry = new ZipEntry(cleanName);
zipEntry.DateTime = fileInfo.LastWriteTime;
zipEntry.Size = fileInfo.Length;
zipStream.PutNextEntry(zipEntry);
byte[] numArray = new byte[4096];
using (FileStream fileStream = File.OpenRead(file))
{
StreamUtils.Copy(fileStream, zipStream, numArray);
}
zipStream.CloseEntry();
}
foreach (string directory in directories)
{
CompressFolder(directory, zipStream, folderOffset);
}
}

Gina Marano
- 1,773
- 4
- 22
- 42
0
See http://community.sharpdevelop.net/forums/p/10856/29901.aspx where (I quote): "Our current roadmap includes UTF entry filename handling [...]" Which would lead me to understand that UTF filenames are not currently supported.

apaderno
- 28,547
- 16
- 75
- 90

Jamie Howarth
- 3,273
- 3
- 20
- 26
-
1Thanx, I kno that using ZipOutputStream we can zip files with UTF8 name, but the question is how I can allow to zip empty folders too?? – BreakHead Jan 11 '11 at 13:31