SharpZipLib 以前叫做 NZipLib ,是個好用的壓縮/解壓縮套件,並且可以設定密碼,支援 .NET 6 。
將 zip 檔案壓縮:
參考資料:
GitHub - icsharpcode/SharpZipLib
安裝
先使用 NuGet 安裝 SharpZipLib 套件,或是使用 .NET CLI 執行以下指令安裝
dotnet add package SharpZipLib
示範
將資料夾壓縮為 zip 檔案:
// 來源路徑
string sourceFolder = @"C:\Users\ruyut\Downloads\新增資料夾";
// zip 檔案路徑
string zipFilePath = @"C:\Users\ruyut\Downloads\新增資料夾.zip";
FastZip fastZip = new FastZip();
fastZip.CreateZip(zipFilePath, sourceFolder, true, "");
將 zip 檔案壓縮:
// zip 檔案路徑
string zipFilePath = @"C:\Users\ruyut\Downloads\新增資料夾.zip";
// 解壓縮的目標資料夾
string extractFolder = @"C:\Test\Extract";
FastZip fastZip = new FastZip();
fastZip.ExtractZip(zipFilePath, extractFolder, "");
參考資料:
GitHub - icsharpcode/SharpZipLib
感謝分享~
回覆刪除