zip (ICSharpCode.SharpZipLib.dll文件需要下载)
ZipClass zc=new ZipClass ();
zc.ZipDir(@"E:\1\新建文件夹", @"E:\1\新建文件夹.zip", 1);//压缩
zc.UnZip(@"E:\1\新建文件夹.zip",@"E:\1\2222");//解压
cs
![](/assets/blank.gif)
![](/assets/blank.gif)
1 class ZipClass 2 { 3 public void UnZip(string zipFilePath, string unZipDir) 4 { 5 if (zipFilePath == string.Empty) 6 { 7 throw new Exception("压缩文件不能为空!"); 8 } 9 if (!File.Exists(zipFilePath)) 10 { 11 throw new System.IO.FileNotFoundException("压缩文件不存在!"); 12 } 13 //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 14 if (unZipDir == string.Empty) 15 unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath)); 16 if (!unZipDir.EndsWith("//")) 17 unZipDir += "//"; 18 if (!Directory.Exists(unZipDir)) 19 Directory.CreateDirectory(unZipDir); 20 21 using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath))) 22 { 23 24 ZipEntry theEntry; 25 while ((theEntry = s.GetNextEntry()) != null) 26 { 27 string directoryName = Path.GetDirectoryName(theEntry.Name); 28 string fileName = Path.GetFileName(theEntry.Name); 29 if (directoryName.Length > 0) 30 { 31 Directory.CreateDirectory(unZipDir + directoryName); 32 } 33 if (!directoryName.EndsWith("//")) 34 directoryName += "//"; 35 if (fileName != String.Empty) 36 { 37 using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name)) 38 { 39 40 int size = 2048; 41 byte[] data = new byte[2048]; 42 while (true) 43 { 44 size = s.Read(data, 0, data.Length); 45 if (size > 0) 46 { 47 streamWriter.Write(data, 0, size); 48 } 49 else 50 { 51 break; 52 } 53 } 54 } 55 } 56 } 57 } 58 } 59 60 61 62 public static void ZipDir(string sDir, string sZip, ZipOutputStream s) 63 { 64 string[] filenames = Directory.GetFiles(sDir); 65 string[] dirnames = Directory.GetDirectories(sDir); 66 Crc32 crc = new Crc32(); 67 if (s == null) 68 { 69 s = new ZipOutputStream(File.Create(sZip)); 70 s.SetLevel(6); // 0 - store only to 9 - means best compression 71 } 72 73 74 foreach (string file in filenames) 75 fileZipInStream(file, s); 76 77 foreach (string dir in dirnames) 78 ZipDir(dir, "", s); 79 if (sZip != "") 80 { 81 s.Finish(); 82 s.Close(); 83 84 FileInfo fInfo = new FileInfo(sZip); 85 long size = fInfo.Length; 86 //Log.WriteLogD("----------------" + size.ToString()); 87 if (size < 100) 88 File.Delete(sZip); 89 } 90 } 91 92 }
View Code
ICSharpCode.SharpZipLib.dll下载地址:http://i.cnblogs.com/Files.aspx
感谢提供此类的朋友
转载于:https://www.cnblogs.com/yuanjiehot/p/4320976.html
zip (ICSharpCode.SharpZipLib.dll文件需要下载)相关推荐
- C# ZipHelper C#公共类 -- ICSharpCode.SharpZipLib.dll实现压缩和解压
关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 1.基本介绍 由于项目中需要用到各种压缩将文件 ...
- ICSharpCode.SharpZipLib.dll,MyZip.dll,Ionic.Zip.dll 使用
MyZip.dll : 有BUG,会把子目录的文件解压到根目录.. ICSharpCode.SharpZipLib.dll: 把ICSharpCode.SharpZipLib.dll复制一份,重命名为 ...
- 使用ICSharpCode.SharpZipLib.dll实现在线解压缩
ICSharpCode.SharpZipLib.dll 是一个基于GNU的免费库文件,他的功能很强大. 下载地址:http://www.icsharpcode.net/OpenSource/Sharp ...
- C#利用ICSharpCode.SharpZipLib.dll压缩文件和解压文件
/// <summary> /// 压缩文件 /// </summary> using System; using System.IO; using ICSharpCode ...
- C# 利用ICSharpCode.SharpZipLib.dll 实现压缩和解压缩文件
我们 开发时经常会遇到需要压缩文件的需求,利用C#的开源组件ICSharpCode.SharpZipLib, 就可以很容易的实现压缩和解压缩功能. 压缩文件: /// <summary> ...
- 使用ICSharpCode.SharpZipLib对文件进行压缩或解压
简介: #ziplib(SharpZipLib,原名NZipLib)是zip,gzip,rar和bzip2压缩库 完全用C#语言编写的.NET平台. 这是作为一个程序集(在GAC中安装),因此可以很容 ...
- 计算机提示msvcp110.dll文件丢失下载安装修复教程
电脑打开一个浏览器后在顶部网址栏目输入[dll修复程序.site]按下键盘的回车键打开前往. 下载完成的修复工具需要对其进行压缩,解压好了以后打开工具. 打开修复工具后,可以看到右边修复与检测的项目, ...
- C#使用ICSharpCode.SharpZipLib.dll压缩文件夹和文件
大家可以到http://www.icsharpcode.net/opensource/sharpziplib/ 下载SharpZiplib的最新版本,本文使用的版本为0.86.0.518,支持Zip, ...
- Dll文件缺失下载地址
最近遇到了缺失文件,如果有需要可以在这里面搜索了进行下载. Download missing DLL files for free | DLL‑files.com (dll-files.com) 对于 ...
最新文章
- 扒皮下京东首页楼层图标的动画效果实现方式
- VTK一个面向对象的可视化类库
- Cloudera Manager 和CDH6.0.1安装,卸载,各步骤截图(此博文为笔者辛苦劳作最终生成的,使用了3个熬到凌晨2~4点的夜晚,外加一个周末完成,请转载时记录转载之处,谢谢)
- linux打包压缩命令有哪些,Linux压缩打包命令使用方法有哪些呢?
- 关于“三门问题”的一些想法
- 【LeetCode笔记】31. 下一个排列(Java、原地算法、偏数学)
- 《追风筝的人》卡勒德·胡赛尼著小说成长的故事
- IOS中的数据存储 简单总结
- OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
- Windows基于gitee使用hexo搭建个人博客笔记
- MTK: mtk 10A 建立socket连接问题
- 【汇编语言与计算机系统结构笔记08】如何实现循环(Loops),gcc历史上经历了多种转换模式(微体系结构角度解释),Switch语句,跳转表
- java基础知识补漏(1)---内部类,重写、重载
- Android Studio新手教程
- 制作u盘启动盘对u盘有什么影响
- 锦天科技被盛大收购 23岁创始人成亿万富翁
- 动态规划 DEMO 投资分配问题
- 大白话式粗浅地聊聊NLP语言模型
- 像素级图像融合常用方法
- UE5中创建VR项目并在瞬移的基础上增加圆盘位移操作