c 解壓zip 進度 C 實現Zip壓縮解壓例項

2021-10-13 08:25:15 字數 2831 閱讀 2704

1 usingsystem;2 usingsystem.collections.generic;3 usingsystem.linq;4 usingsystem.text;5 usingsystem.io;6 usingicsharpcode.sharpziplib;7 usingicsharpcode.sharpziplib.zip;8 usingicsharpcode.sharpziplib.checksums;9

10 namespacecleopardzip11 60

61 }62 catch

63 66 finally

67 73 if (ent != null)74 77 gc.collect();78 gc.collect(1);79 }80

81 folders =directory.getdirectories(foldertozip);82 foreach (string folder infolders)83 if (!zipdirectory(folder, zipstream, foldertozip))84 return false;85

86 returnresult;87 }88

89 ///

90 ///壓縮資料夾91 ///

92 /// 要壓縮的資料夾路徑

93 /// 壓縮檔案完整路徑

94 /// 密碼

95 /// 是否壓縮成功

96 public static bool zipdirectory(string foldertozip, string zipedfile, stringpassword)97 113

114 ///

115 ///壓縮資料夾116 ///

117 /// 要壓縮的資料夾路徑

118 /// 壓縮檔案完整路徑

119 /// 是否壓縮成功

120 public static bool zipdirectory(string foldertozip, stringzipedfile)121 125

126 ///

127 ///壓縮檔案128 ///

129 /// 要壓縮的檔案全名

130 /// 壓縮後的檔名

131 /// 密碼

132 /// 壓縮結果

133 public static bool zipfile(string filetozip, string zipedfile, stringpassword)134 160 catch

161 164 finally

165 171 if (ent != null)172 175 if (fs != null)176 180 }181 gc.collect();182 gc.collect(1);183

184 returnresult;185 }186

187 ///

188 ///壓縮檔案189 ///

190 /// 要壓縮的檔案全名

191 /// 壓縮後的檔名

192 /// 壓縮結果

193 public static bool zipfile(string filetozip, stringzipedfile)194 198

199 ///

200 ///壓縮檔案或資料夾201 ///

202 /// 要壓縮的路徑

203 /// 壓縮後的檔名

204 /// 密碼

205 /// 壓縮結果

206 public static bool zip(string filetozip, string zipedfile, stringpassword)207 216

217 ///

218 ///壓縮檔案或資料夾219 ///

220 /// 要壓縮的路徑

221 /// 壓縮後的檔名

222 /// 壓縮結果

223 public static bool zip(string filetozip, stringzipedfile)224 229

230 #endregion

232 #region 解壓

234 ///

235 ///解壓功能(解壓壓縮檔案到指定目錄)236 ///

237 /// 待解壓的檔案

238 /// 指定解壓目標目錄

239 /// 密碼

240 /// 解壓結果

241 public static bool unzip(string filetounzip, string zipedfolder, stringpassword)242 274 if (tmpdir ==filename)275 278 }279

280 fs =file.create(filename);281 int size = 2048;282 byte data = new byte[size];283 while (true)284 291 }292 }293 }294 catch

295 298 finally

299 305 if (zipstream != null)306 310 if (ent != null)311 314 gc.collect();315 gc.collect(1);316 }317 returnresult;318 }319

320 ///

321 ///解壓功能(解壓壓縮檔案到指定目錄)322 ///

323 /// 待解壓的檔案

324 /// 指定解壓目標目錄

325 /// 解壓結果

326 public static bool unzip(string filetounzip, stringzipedfolder)327 331

332 #endregion

333 }334 }

c 解壓zip 進度 C 壓縮解壓zip 檔案

1 2 zip 壓縮檔案3 4 public classzip5 10 region 加壓方法 11 14 被壓縮的資料夾夾路徑 15 生成壓縮檔案的路徑,為空則預設與被壓縮資料夾同一級目錄,名稱為 資料夾名 zip 16 出錯資訊 17 是否壓縮成功 18 public static bool z...

C 實現Zip檔案解壓

首先需要安裝7 zip。7 zip是一款高壓縮比的壓縮軟體,不僅支援獨有的7z檔案格式,而且還支援各種其它壓縮檔案格式,其中包括 zip rar cab gzip bzip2和tar等格式。此軟體壓縮的壓縮比要比普通zip檔案高30 50 方式一 解壓zip檔案 public static void...

C 使用SharpZipLib實現zip壓縮

使用國外開源加壓解壓庫icsharpcode.sharpziplib實現加壓,該庫的官方 為 使用體驗 可以照著例子實現簡單的加壓解壓,可以加壓乙個資料夾中的所有檔案,但沒有提供加壓子資料夾的說明。目前網上的一些 有的無法加壓空資料夾,有的加壓了用rar解不開,這是一點需要改進的。但如果只需要加壓資...