ZipArchive 的使用
新建一个项目,首先添加 System.IO.Compression.FileSystem 引用。
解压文件
using System.IO.Compression;
namespace cl
{
static void Main()
{
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
压缩单个文件
using System;
using System.IO.Compression; namespace cl
{
sealed class ZipCreater
{
static void Main()
{
using (var zip = ZipFile.Open("ZipCreater.zip", ZipArchiveMode.Create))
{
zip.CreateEntryFromFile(@"C:\work\ZipCreater.cs", "ZipCreater.cs");
zip.CreateEntryFromFile("ZipCreater.exe", "ZipCreater.exe");
}
}
}
}
压缩文件夹
using System;
using System.IO.Compression; namespace cl
{
sealed class Zip
{
static void Main(string[] args)
{
if (args.Length != )
{
Console.WriteLine("Usage: Zip zip-file-name directory-name");
return;
}
try { ZipFile.CreateFromDirectory(args[], args[]); }
catch (Exception ex) { Console.Error.WriteLine(ex.Message); }
}
}
}
参考文章:
浅谈 ZipArchive 类 - 银河 - 博客园
http://www.cnblogs.com/skyivben/archive/2012/03/09/2388482.html
ZipArchive 的使用的更多相关文章
- 文件打包,下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件
总结: 使用PHP下载文件的操作需要给出四个header(),可以参考我的另一篇博文: ...
- ZipArchive之C++编译和调用
由于要用到zip的解压,就上网下载了CZipArchive类的源码(还是2000年的),里面有个示例,稍微修改下,就能正常运行. 就高兴地把lib拿出来,放到项目中了.捣鼓了快一个下午了,死活编译不通 ...
- ZipArchive 打包下载压缩包
用php的header()方式下载压缩包. 要点:1.不能在header导出压缩包前向浏览器输出内容,否则文件下载压缩包成功,打开的压缩包也会显示被破坏. 2.在压缩文件包的php代码前不可以有js脚 ...
- iOS开发——网络篇——文件下载(NSMutableData、NSFileHandle、NSOutputStream)和上传、压缩和解压(三方框架ZipArchive),请求头和请求体格式,断点续传Range
一.小文件下载 NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/resources/images/minion ...
- ZipArchive和SSZipArchive使用详解
一.SSZipArchive 1.简介 SSZipArchive是iOS和Mac上一个简单实用的压缩和解压插件.用途包括:1.解压zip文件:2.解压密码保护的ZIP文件:3.创建新的zip文件:4. ...
- zipArchive
ZipArchive *unZip = [[ZipArchive alloc]init]; if ([unZip unzipOpenFile:savePath]) { BOOL ret = [unZi ...
- 代码演示用 .NET 4.5 (C# 5.0)自带的压缩类 ZipArchive 创建一个压缩文件
代码如下: using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; ...
- ZipArchive框架的文件压缩和解压
导入第三方框架ZipArchive之后还要在系统库文件中导入一个如下文件(搜索libz出来的任何一个都可以) 导入的头文件是#import "Main.h" 文件压缩 -(vo ...
- Fatal error: Class 'ZipArchive' not found的解决办法
今天在Linux底下编写导出EXCEL文件并显示输出时,抛出“ZipArchive library is not enabled” 的异常.而我在本地的windows下的代码则是运行正常的. 原因是: ...
随机推荐
- JavaEE通过response实现请求重定向
请求重定向指的是一个web资源收到客户端请求后,通知客户端去访问另外一个web资源,这称之为请求重定向.302状态码和location头即可实现重定向. 请求重定向最常见的应用场景就是用户登录. 下面 ...
- MyBatis之二:简单增删改查
这一篇在上一篇的基础上简单讲解如何进行增删改查操作. 一.在mybatis的配置文件conf.xml中注册xml与注解映射 <!-- 注册映射文件 --> <mappers> ...
- [AngularJS] Directive using another directive by 'require'
Directive can use another directive though 'require' keyword. angular.module('docsTabsExample', []) ...
- Android进阶2之APK方式换肤
public class MainActivity extends Activity { private Button defaultbutton = null; @Override public v ...
- iOS开发——数据持久化&使用NSUserDefaults来进行本地数据存储
使用NSUserDefaults来进行本地数据存储 NSUserDefaults适合存储轻量级的本地客户端数据,比如记住密码功能,要保存一个系统的用户名.密码.使用NSUserDefaults是首 ...
- python selenium自动化(二)自动化注册流程
需求:使用python selenium来自动测试一个网站注册的流程. 假设这个网站的注册流程分为三步,需要提供比较多的信息: 在这个流程里面,需要用户填入信息.在下拉菜单中选择.选择单选的radio ...
- VIM标记 mark 详解
转载:http://blog.163.com/lgh_2002/blog/static/44017526201081154512135/ 我的vim配置:http://pan.baidu.com/s/ ...
- Mac 下配置Tomcat7和eclipse中配置tomcat
转载自: http://www.cnblogs.com/weilaikeji/archive/2013/05/29/3106473.html 1.下载Tomcat 从Tomcat项目主页下载相关压缩包 ...
- 炼数成金hadoop视频干货04
视频地址:http://pan.baidu.com/s/1dDEgKwD 这一节讲的全是理论 任务执行优化 : 1.推测式执行: 2.重用JVM: 3.忽略模式. 除了手动修改Log4J.proper ...
- Collections.synchronizedMap 详解
众所周知,HashMap 本身非线程安全的,但是当使用 Collections.synchronizedMap(new HashMap()) 进行包装后就返回一个线程安全的Map. 怎么实现的呢?今天 ...