c#用 Dotnatzip 來壓縮含所有下面子目錄

請教...

這是 c#用 Dotnatzip 來壓縮,但我要把它下面的子目錄也全部壓縮進來,應該是要用 zip.AddDirectory(),腦袋想破頭不知要如何寫?
請高手指點一下...

tks.




private static void Compress_Dotnatzip(string target_pathname, string source_pathname)
{
string zipPath = string.Format("{0}{1}.zip", target_pathname,DateTime.Now.ToString("yyyyMMddHHmmss"));


ZipFile zip = new ZipFile();

ArrayList files = GetFiles(source_pathname);

foreach (string f in files)
{
zip.AddFile(f, string.Empty);//第二個參數設為空值表示壓縮檔案時不將檔案路徑加入
}

zip.Save(zipPath);

}



2015-06-19 11:07 發佈
幫你Google來的,正不正確請自己驗證

public void ZipUp(string targetZip, string directory)
{
using (var zip = new ZipFile())
{
zip.AddDirectory(directory, System.IO.Path.GetFileName(directory));
zip.Save(targetZip);
}
}

Wesley Hsu wrote:
幫你Google來...(恕刪)


Wesley Hsu 大大您好:

這段code我也有找到,本來想是要先把所有目錄全部找出來,再逐一壓縮...結果發現原來用 zip.AddDirectory(); 它就全部幫我壓縮好了,真是方便,連前面的 zip.AddFile() 都省了

不過遇到中文亂碼,我用Encoding.UTF8 解決了...

TKS.
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?