//https://archive.codeplex.com/?p=dotnetzip
//最新在Nuget 下载DotNetZip using Ionic.Zip; private void button1_Click(object sender, EventArgs e)
{
string msg = "";
ExtractFile("D:\\1.zip", "d:\\OK\\");
ExtractFile("D:\\1.zip", "d:\\OK\\", false, out msg);
} public static bool ZipFolder(
String sourceFilePath,
String targetFileFullPath,
Boolean isUsePassword,
Int32 maxOutputSegmentSiez,
out String errMessage)
{
try
{
using (ZipFile zip = new ZipFile(Encoding.Default))
{
errMessage = String.Empty;
zip.Comment = "压缩文件时间" + System.DateTime.Now.ToString("G");
zip.Name = Guid.NewGuid().ToString().ToUpper() + ".zip";
if (isUsePassword)
zip.Password = "123";
zip.MaxOutputSegmentSize = maxOutputSegmentSiez * 1000;
zip.BufferSize = 1024;
zip.CaseSensitiveRetrieval = true;
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddDirectory(sourceFilePath);
zip.Save(targetFileFullPath);
return true;
}
}
catch (Exception ex) { errMessage = ex.Message; return false; }
} public static bool ExtractFile(String sourceFileFullPath, String targetFolderPath, Boolean isUsePassword, out String errMessage)
{
try
{
Encoding encoding = Encoding.UTF8;
errMessage = String.Empty;
var options = new ReadOptions { StatusMessageWriter = System.Console.Out, Encoding = encoding };
using (ZipFile zip = ZipFile.Read(sourceFileFullPath, options))
{
if (isUsePassword)
{ //假设有密码123
zip.Password = "123";
}
zip.AlternateEncoding = encoding;
zip.ExtractAll(targetFolderPath, ExtractExistingFileAction.OverwriteSilently);//一次批量解压
return true;
}
}
catch (Exception ex) { errMessage = ex.Message; return false; }
} public static bool ExtractFile(String sourceFileFullPath, String targetFolderPath)
{
try
{
Encoding encoding = Encoding.UTF8; var options = new ReadOptions { StatusMessageWriter = System.Console.Out, Encoding = encoding };
using (ZipFile zip = ZipFile.Read(sourceFileFullPath, options))
{
zip.AlternateEncoding = encoding;
foreach (var f in zip.Entries)
{//一个个解压
f.Extract(targetFolderPath, ExtractExistingFileAction.OverwriteSilently);
} return true;
}
}
catch (Exception ex)
{ return false;
}
}

  

c# 用DotNetZip来解压/压缩文件的更多相关文章

  1. linux解压/压缩文件

    1.*.tar 用 tar –xvf 解压  2.*.gz 用 gzip -d或者gunzip 解压  3.*.tar.gz和*.tgz 用 tar –xzf 解压  4.*.bz2 用 bzip2 ...

  2. Qt 解压/压缩文件

    很久没有在博客园写随笔了,今天项目需要解压和压缩文件,所以去了解哈. 参考的是大神的代码:https://yq.aliyun.com/articles/24428. 使用的是 QuaZIP类. 类 说 ...

  3. 解压压缩文件报错gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now

    压缩包是直接weget 后面加官网上的tar包地址获取的  [root@xuegod43 ~]# tar -zxvf /home/hadoop/hadoop-2.6.5-src.tar.gz gzip ...

  4. Linux 解压 压缩文件

    来源于:http://blog.csdn.net/mmllkkjj/article/details/6768294/ 解压 tar –xvf file.tar //解压 tar包tar -xzvf f ...

  5. Bug :”解压压缩文件失败: cpio; 在头中不存在归档“

    问题描述: 在rpm包目录下执行rpm -ivh *rpm -force时,出现标题错误 解决办法: *src.rpm包也就源码包不能被直接进行安装,需要先将src.rpm包进行编译生成二进制的rpm ...

  6. Linux解压rar文件

    Linux解压rar文件(unrar安装和使用,分卷解压) windows平台很多压缩文档为rar文件,那么怎么做到Linux解压rar文件(unrar安装和使用)? 简单,centos5安装unra ...

  7. Java 压缩/ 解压 .Z 文件

    1.问题描述 公司项目有需要用 JAVA 解压 .z文件. .z 是 unix 系统常见的压缩文件. 2.源码 import com.chilkatsoft.CkUnixCompress; impor ...

  8. (转载)C#压缩解压zip 文件

    转载之: C#压缩解压zip 文件 - 大气象 - 博客园http://www.cnblogs.com/greatverve/archive/2011/12/27/csharp-zip.html C# ...

  9. tar 多文件解压压缩

    tar 多文件解压:因为tar -zxvf一次值能解压一个文件,所以用xargs -n1 .先查找 ls *gz | xargs -n1 tar -zxvf .要解压的文件在list中 cat lis ...

随机推荐

  1. Python 入门之 闭包

    Python 入门之 闭包 1.闭包 (1)在嵌套函数内使用(非本层变量)和非全局变量就是闭包 (2)_ closure _ 判断是不是闭包 def func(): a = 1 def foo(): ...

  2. linux:服务器代理squid安装配置

    国内上往外的网站太慢,配了个香港代理服务器.如下:当前环境: centos系统.香港服务器IP(假设:59.188.71.11)检查squid是否安装:[root@localhost ~]# rpm ...

  3. idea无法使用注解@Data解决方法

    @Data相关依赖 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lomb ...

  4. Vue环境搭建和项目创建

    目录 vue项目 环境搭建 项目创建 vue项目 环境搭建 node node ~~ python:node是用c++编写用来运行js代码的 npm(cnpm) ~~ pip:npm是一个终端应用商城 ...

  5. 2014-04-27 南江滨大道 6KM 晴

    33分41秒,6.03公里,慢速跑,中间有停了几次拍照 天气不错,多云 人,不多 不知道这货叫啥 2个大人3个小孩,跳绳,小时候的回忆,啊哈 老中少三代,捡风筝也是一种幸福 一家三口,江滨散步,惬意至 ...

  6. NSURLSession断点下载

    #import <Foundation/Foundation.h> @class XHDownLoadManager; #pragma mark - delegate Method @pr ...

  7. JAVA中关于日期的最常见的操作

    //获取当前系统的时间戳 long times = System.currentTimeMillis(); //创建一个当前日期对象 Date now = new Date(); //基于指定的时间戳 ...

  8. 长沙理工大学第十二届ACM大赛L 选择困难症 (剪枝暴搜)

    链接:https://ac.nowcoder.com/acm/contest/1/L 来源:牛客网 选择困难症 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 131072K,其他语言 ...

  9. Candidate Generation and LUNA16 preprocessing

    在这个kernel中,我们将讨论有助于更好地理解问题陈述和数据可视化的方法. 我还将提供有用的资源和信息的链接. 此脚本是用Python编写的. 我建议人们在桌面上安装anaconda,因为here提 ...

  10. warning MSB8030: The linker switch "Minimum Required Version" requires "SubS

    In the project properties, under Linker -> System, make sure that you set the SubSystem property ...