2012-02-16 48 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(); 

我沒有測試解壓縮。