原文連結:https://blog.csdn.net/jk007/article/details/30251963
using ICSharpCode.SharpZipLib.Zip;
public static void CompressDirectory(string iDirectory, string oFile)
{
FastZip fastzip = new FastZip();
Create Empty Directory
fastzip.CreateEmptyDirectories = true;
fastzip.CreateZip(oFile, iDirectory, true, string.Empty);
}
public static void DecompressDirectory(string iFile, string oDirectory)
{
FastZip fastzip = new FastZip();
Create Empty Directory
fastzip.CreateEmptyDirectories = true;
fastzip.ExtractZip(iFile, oDirectory, string.Empty);
}
相關知識:
ZipFile類用於選擇檔案或資料夾進行壓縮生成壓縮包。
FastZip用於快速壓縮目錄,有一個方法CreateZip.
引數說明:
zipFileName:生成的壓縮檔案
sourceDirectory:待壓縮的資料夾
recurse:是否遍歷子目錄,True就遍歷,False則不遍歷
fileFilter:檔案過濾,即決定那些字尾的檔案被壓縮
ZipOutputStream:相當於一個壓縮包;
ZipEntry:相當於壓縮包裡的一個檔案;