2012-02-16 50 views

回答

2
FastZip fastZip = new FastZip(); 

fastZip.CreateEmptyDirectories = true; 
// Include all files by recursing through the directory structure 
bool recurse = true; 
// Dont filter any files at all 
string filter = null; 
fastZip.CreateZip("fileName.zip", @"C:\SourceDirectory", recurse, filter); 

一个需要注意的是它无法处理UTF-8文件名。

这里是链接到文档网站:

http://wiki.sharpdevelop.net/SharpZipLib_FastZip.ashx

+0

只有名称不能使用utf-8或内容吗?我可以打包名为'aa.txt'的文件是utf-8文本文件吗? – nirmus 2012-02-16 01:02:14

+0

@nirmus - 只是文件名。 – 2012-02-16 01:07:14

+0

非常感谢,现在在zip我有空目录,但如果我使用FastZip.ExtractZip没有空目录;)有趣; p – nirmus 2012-02-16 01:15:26

2

您可以将程序添加的文件夹为条目。

将下面的代码添加到每个文件夹的循环中。

//Here we create a path for a new entry, 
//but this time with the '\' in the end, its a folder 
string sEntry = sFolder.Substring(iFolderOffset) + "\\"; 
sEntry = ZipEntry.CleanName(sEntry); 
ZipEntry zeOutput = new ZipEntry(sEntry); 
zsOutput.PutNextEntry(zeOutput); 
zsOutput.CloseEntry(); 

我没有测试解压缩。