压缩解压目录和文件--ICSharpCode.SharpZipLib.dll 算法 (转)

Unity 工具 之 (SharpZipLib) 实现文件Zip的压缩和解压((可代密码)可一次压缩多个文件/文件夹) Unity 工具 之 (SharpZipLib) 实现文件Zip的压缩和解压(可压缩多个文件) 一、简单介绍 Unity 工具类,自己整理的一些游戏开发可能用到的模块,单独独立使用,方便游戏开发。 使用SharpZipLib库,下载地址为:http://icsharpcode.github.io/SharpZipLib/ ... 阅读详情

ICSharpCode.SharpZipLib.dll实现压缩解压一个树形目录

 

//压缩

using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using System.Collections;
namespace ZipSharpLibray.Common.Control
{
///
/// Class1 的摘要说明。
///
public class FileZipCreate
{
private static FileZipCreate filezipcreate=null;
private string zipfilecreatename;
private string filesdirectorypath;
private int dirnamelength = 0;
private int ziplevel = 6;
private FileZipCreate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///
/// 压缩后的文件的全名称
///
public string ZipFileCreateName
{
set
{
this.zipfilecreatename=value;
}
get
{
return this.zipfilecreatename;
}
}
///
/// 待压缩文件目录
///
public string FileDirectoryPath
{
set
{
this.filesdirectorypath=value;
}
get
{
return this.filesdirectorypath;
}
}
public int ZipLevel
{
set
{
this.ziplevel=value;
}
get
{
return this.ziplevel;
}
}
public static FileZipCreate ZipFileInstance()
{

if(filezipcreate==null)
{
filezipcreate=new FileZipCreate();
}
return filezipcreate;
}
///
/// 压缩文件的方法
///
public void ZipFileCreate()
{
ZipOutputStream zipoutputstream= new ZipOutputStream(File.Create(this.zipfilecreatename));
zipoutputstream.SetLevel(this.ziplevel);
Crc32 crc = new Crc32();
Hashtable fileList=this.getAllFies();
foreach (DictionaryEntry item in fileList)
{
FileStream fs = File.OpenRead(item.Key.ToString());
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(item.Key.ToString().Substring(this.filesdirectorypath.Length-this.dirnamelength));
entry.DateTime = (DateTime)item.Value;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
zipoutputstream.PutNextEntry(entry);
zipoutputstream.Write(buffer, 0, buffer.Length);
}
zipoutputstream.Finish();
zipoutputstream.Close();
}
///
/// 获取所有文件
///
///
private Hashtable getAllFies()
{
Hashtable FilesList = new Hashtable();
DirectoryInfo fileDire = new DirectoryInfo(this.filesdirectorypath);
if(!fileDire.Exists)
{
throw new System.IO.FileNotFoundException("目录:"+ fileDire.FullName + "没有找到!");
}
this.dirnamelength=fileDire.Name.Length;
this.getAllDirFiles(fileDire,FilesList);
this.getAllDirsFiles(fileDire.GetDirectories(),FilesList);
return FilesList;
}
///
/// 获取一个文件夹下的所有文件夹里的文件
///
/// /// private void getAllDirsFiles(DirectoryInfo[] dirs, Hashtable filesList)
{
foreach (DirectoryInfo dir in dirs)
{
foreach (FileInfo file in dir.GetFiles("*.*"))
{
filesList.Add(file.FullName,file.LastWriteTime);
}
this.getAllDirsFiles(dir.GetDirectories(),filesList);
}
}
///
/// 获取一个文件夹下的文件
///
/// 目录名称 /// 文件列表HastTable private void getAllDirFiles(DirectoryInfo dir,Hashtable filesList)
{
foreach (FileInfo file in dir.GetFiles("*.*"))
{
filesList.Add(file.FullName, file.LastWriteTime);
}
}
}
}


//解压

using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;

namespace ZipSharpLibray.Common.Control
{
///
/// UZipFilesCreate 的摘要说明。
///
public class UZipFilesCreate
{
private string zipfilename;
private string filescreatepath;
private static UZipFilesCreate uzipfilescreate=null;
private UZipFilesCreate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
///
/// Zip文件目录
///
public string ZipFileName
{
set
{
this.zipfilename=value;
}
get
{
return this.zipfilename;
}
}
///
/// 解压文件目录
///
public string filesCreatePath
{
set
{
this.filescreatepath=value;
}
get
{
return this.filescreatepath;
}
}
public static UZipFilesCreate UZipFilesInstance()
{
if(uzipfilescreate==null)
{
uzipfilescreate=new UZipFilesCreate();
}
return uzipfilescreate;
}
public void UZipCreateFiles()
{
ZipEntry entry;
ZipInputStream zipinputstream = new ZipInputStream(File.OpenRead(this.zipfilename));
while ((entry = zipinputstream.GetNextEntry()) != null)
{
this.CreateDirList(entry.Name);
string strPath=this.filescreatepath+"//"+entry.Name;
FileStream streamWriter =File.Create(strPath);
byte[] data = new byte[entry.Size];
zipinputstream.Read(data, 0, data.Length);
streamWriter.Write(data, 0, data.Length);
streamWriter.Close();
File.SetLastWriteTime(strPath,entry.DateTime);
}
zipinputstream.Close();
}
private void CreateDirList(string filename)
{
string dirName=this.filescreatepath;
string[] dirlevelname=filename.Split('//');
for(int i=0;i {
dirName+="//"+dirlevelname[i];
if(Directory.Exists(dirName))
{
continue;
}
Directory.CreateDirectory(dirName);
}
}
}
}

//调用

using ZipSharpLibray.Common.Control;

......

private void Button1_Click(object sender, System.EventArgs e)
{

//压缩
FileZipCreate filezipcreate=FileZipCreate.ZipFileInstance();
filezipcreate.ZipFileCreateName=Server.MapPath(DateTime.Now.ToString("yyyyMMddmmss")+".zip");
filezipcreate.FileDirectoryPath=Server.MapPath("../Admin/Css");
filezipcreate.ZipFileCreate();
}

private void Button2_Click(object sender, System.EventArgs e)
{

//解压
UZipFilesCreate uzipfilescreate=UZipFilesCreate.UZipFilesInstance();
uzipfilescreate.ZipFileName=this.File1.PostedFile.FileName.Trim();
uzipfilescreate.filesCreatePath=Server.MapPath("");
uzipfilescreate.UZipCreateFiles();
}

.Net 下利用ICSharpCode.SharpZipLib.dll实现文件、文件夹压缩、解压缩 添加引用ICSharpCode.SharpZipLib.dll using System; using System.Collections.Generic; using System.IO; using System.Threading; using ICSharpCode.SharpZipLib.Zip; namespace Lib { /// /// 文件压缩、解压 阅读详情

相关推荐

Unity 用ICSharpCode.SharpZipLib 解压zip文件遇到的坑

Unity在编辑器模式下运行解压网络下载的zip压缩包都没有问题,打包出来以后解压就不产生作用,找了好久才解决 一、引用的库文件:I18N.CJK.dll,I18N.dll ,I18N.West.dll ,Mono.Data.Tds.dll,System.Data.dll这五个DLL 加入到Plugins文件夹中。 这五个库文件内容所在地址为:XXX\Unity\Editor\Data\Mon...

chh19941125的专栏 3983

C# 下利用ICSharpCode.SharpZipLib.dll实现文件/文件夹压缩、解压缩

ICSharpCode.SharpZipLib.dll下载地址 1、压缩某个指定目录下日志 #region 压缩logs目录下日志 public static void CompresslogDic() { try { string logFilePath =

勿忘初心 4789

ZipHelper压缩解压缩

需要引用 DLL-ICSharpCode.SharpZipLib   下载地址http://download.csdn.net/download/cleopard/8304539         using System; using System.Collections.Generic; using System.Text; using ICSharpCode.SharpZipLib.Zip;

sinat_15155817的专栏 1825

ICSharpCode.SharpZipLib 压缩、解压文件 附源码

http://www.icsharpcode.net/opensource/sharpziplib/有SharpZiplib的最新版本,本文使用的版本为0.86.0.518,支持Zip, GZip, BZip2 和Tar格式 我们需要dll 在官网上也有,也可以从百度网盘下载 好了,深入的大家还要多多研究,今天我们简单介绍一下 简单的 单文件、文件夹的压缩和解压 先给大家看一下效果:...

weixin_34161064的博客 1210

ICSharpCode.SharpZipLib.dll:C#高效压缩解压库实战应用

ICSharpCode.SharpZipLib 最初由 IC#Code 团队为 .NET 平台开发,旨在填补早期 .NET Framework 在跨平台压缩处理上的空白。其设计遵循轻量、可扩展原则,支持 ZIP、GZIP、BZIP2、Tar 等主流格式,成为许多企业级应用日志归档、资源打包和系统备份的核心组件。

weixin_29069575的博客 1033

C#中使用ICSharpCode.SharpZipLib实现高效解压缩的完整指南

是一个功能强大且轻量级的开源 .NET 压缩库,支持 ZIP、GZIP、BZIP2 和 TAR 等多种压缩格式。其无需依赖外部工具或系统组件,适用于文件打包、日志归档、数据迁移等场景。在企业级应用中,常用于服务端批量处理上传的压缩包或生成报表压缩文件。该库以高可编程性和低内存占用著称,尤其适合需要精细控制解压流程的后台服务与自动化系统。尽管ZipHelper是静态类,但仍需定义若干常量与可配置参数来控制行为特征。这些参数直接影响性能、安全性与兼容性。

weixin_30299319的博客 503

ICSharpCode.SharpZipLi 压缩、解压文件 附源码

http://www.icsharpcode.net/opensource/sharpziplib/有SharpZiplib的最新版本,本文使用的版本为0.86.0.518,支持Zip, GZip, BZip2 和Tar格式 我们需要dll 在官网上也有,也可以从百度网盘下载 好了,深入的大家还要多多研究,今天我们简单介绍一下 简单的 单文件、文件夹的压缩和解压 ...

898

从ESP/ABS选型看轮速传感器:为什么你的车用了AK+PWM+7/14mA三种协议?

本文深入解析了汽车轮速传感器的三种主流协议(7/14mA电流型、PWM型和AK协议型)及其混合应用场景。通过对比不同协议的技术特点、成本效益和工程挑战,揭示了现代车辆采用多种传感器协议背后的设计逻辑,包括成本控制、性能平衡和冗余设计等关键因素。

weixin_29266679的博客 530

Unity游戏资源解压

Unity2017;ICSharpCode.SharpZipLib.Zip; using UnityEngine; using System.Collections; using System.IO; using ICSharpCode.SharpZipLib.Zip; public class ZipTest : MonoBehaviour { pri...

dongbeng5682的博客 536

abb机器人指令手册_ABB机器人配置圆形输送链跟踪

更多内容请点击上方ABB机器人实战技巧关注也可点击公众号下方往期经典浏览更多内容转载请先后台留言,大家一起支持原创,推动机器人使用和发展本公众号对各类ABB机器人应用,仿真,毕业设计提供技术支持,详细后台留言本公众号诚挚希望与各机器人培训机构,机器人使用单元合作,提供技术支持,详细后台留言1. 通常的机器人输送链跟踪,均为直线输送链跟踪,例如下图2. 有些情况,输送链为圆形,例如...

weixin_39849894的博客 2044

正弦波产生电路_文氏桥振荡

本文以文氏桥振荡为基础产生正弦波,介绍了原理、计算、应用时需要注意的一些点,并给出了实测可用的电路模板

白鹤忘机的博客 3万+

C#使用ICSharpCode.SharpZipLib.dll压缩文件夹和文件

using System; using System.Collections.Generic; using System.Linq; using System.Text; using ICSharpCode.SharpZipLib.Zip; using System.IO; using ICSharpCode.SharpZipLib.Checksums; using System.Collecti

人生代码,代码人生。。。 3137

CASIA数据集解析:图像篡改检测的黄金标准与实践指南

本文深入解析了CASIA数据集在图像篡改检测领域的核心价值与应用实践。作为中科院自动化所打造的黄金标准,CASIA数据集通过模拟真实篡改场景(如拼接和复制移动)为研究者提供全面支持。文章详细对比了v1.0与v2.0版本差异,分享数据预处理和模型训练的最佳实践,并探讨了未来研究方向,是图像篡改检测领域的重要参考指南。

kappa的博客 784

使用ICSharpCode.SharpZipLib.dll实现在线解压缩

ICSharpCode.SharpZipLib.dll 是一个基于GNU的免费库文件,他的功能很强大。下载地址:http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx下面是对#ZipLib进行.net下的解压缩的方法的介绍。1.BZip2加入ICSharpCode.SharpZipLib.dll的引用,在#De

寒冬玉 1533

从零到一:用ROS2和Gazebo搭建Franka机械臂仿真环境(避坑指南)

本文详细介绍了如何使用ROS2和Gazebo从零开始搭建Franka机械臂的仿真环境,包括环境准备、ROS2包安装、控制器配置及常见问题解决方案。特别针对关节位置控制等核心功能提供了实用代码示例和避坑指南,帮助开发者高效构建机器人算法验证平台。

weixin_29061465的博客 458

Mac用户福音:三步搞定PyMol开源版,告别许可证弹窗(附Homebrew/MacPorts安装指南)

本文为Mac用户提供三步安装PyMol开源版的详细指南,帮助科研人员告别许可证弹窗烦恼。通过Homebrew或MacPorts包管理器安装开源核心,并与商业版图形界面整合,实现无干扰的分子可视化研究体验。特别适合MacOS用户快速部署PyMol进行结构生物学分析。

weixin_28743405的博客 194

C#利用SharpZipLib解压或压缩文件(支持多层目录递归压缩)

需要下载ICSharpCode.SharpZipLib.dll 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 using Sys...

dingsi7709的博客 565

华为S5700三层交换机VLAN配置避坑指南:为什么你的VLAN间无法互通?

本文针对华为S5700三层交换机VLAN间无法互通的典型故障,提供深度排障指南。文章从数据转发原理入手,系统梳理了从物理链路、VLAN配置、VLANIF接口状态、路由表到ARP表、MTU及安全策略等全链路检查点,并给出了清晰的排查命令与流程,帮助网络工程师快速定位并解决VLAN间路由问题,实现稳定互通。

tt34567的博客 871

.Net 下利用ICSharpCode.SharpZipLib.dll实现文件/文件夹压缩、解压缩(改进)

对原有代码的改进,完善了功能1.增加了压缩文件夹,解压缩文件夹的功能2.解压缩文件时,对目标文件的目录检查,没有则创建 代码如下:using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.W

polarissky的专栏 6710

详解FreeRTOS:低功耗Tickless模式(高级篇—7)

FreeRTOS提供了一个叫做Tickless的低功耗模式,本篇博文我们就来学习一下如何使用这个Tickless模式。

不脱发的程序猿 1896

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Csharp 利用ICSharpCode.SharpZipLib解壓文件

/* *http://www.koders.com/csharp/fid7241B3C8598C20BA18652B5BB5C19D220988E2D4.aspx?s=file * http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx * http://www.eggheadcafe.com/tutorial...

weixin_33932129的博客 198

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

基于(ICSharpCode.SharpZipLib.dll)的文件压缩方法,类文件

CodeusingSystem;usingSystem.IO;usingSystem.Collections;usingICSharpCode.SharpZipLib.Checksums;usingICSharpCode.SharpZipLib.Zip;namespaceFileCompress{///<summary>///功能:压缩文件...

aa520733的博客 169

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

java sharpziplib_ICSharpCode.SharpZipLib.dll 解压缩文件例子 并附完整ISharpZip项目源码

【实例简介】【实例截图】【核心代码】using System;using System.IO;using ICSharpCode.SharpZipLib.Zip;using ICSharpCode.SharpZipLib.Core;namespace Samples.FastZipDemo{class MainClass{enum Operation{Unknown,Create,Extract,...

weixin_36364044的博客 338

使用ICSharpCode.SharpZipLib.dll解压指定文件

class UnZipClass     {         ///         /// 解压缩一个 zip 文件。         ///         /// 待解压文件路径         /// 解压目录         /// *.zip文件的密码         /// 是否覆盖已存在的文件         /// 附加字段         public

Imcx_的博客 1340

利用ICSharpCode.SharpZipLib.dll生成压缩文件

ICSharpCode.SharpZipLib.dll下载: /Files/SweetGan/ICSharpCode.SharpZipLib.rar 引用之后,添加下面的方法,然后调用Zip方法就可以了。 /// <summary> /// 生成压缩文件 /// </summary>...

dmmxtwomdl63644526的博客 188
上一篇: C#的文件读写操作--流方式一次读写文件
下一篇: sql server2000挂起的解决方法
生活真美好
博客等级 码龄26年 227粉丝 124原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值