• 大小: 609KB
    文件类型: .zip
    金币: 2
    下载: 6 次
    发布日期: 2021-05-14
  • 语言: C#
  • 标签: 解压zip  

资源简介

c# 解压zip完整demo 带进度条

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Regularexpressions;
using System.Threading.Tasks;

namespace compressDemo
{
    /// 
    /// 压缩/解压公共类
    /// 

    public class compress
    {
        public compress()
        {

        }

        /// 
        /// 进度委托
        /// 

        /// 
        /// 
        public delegate void UpNum(double index double num);//声明委托
        public UpNum UpNumObj;//委托对象

        public delegate void overDelegate(); //结束的委托
        public overDelegate overD;//委托对象

        /// 
        /// 解压时是否剔除和文件名相同的根目录
        /// 

        public bool isRootPath = false;

        /// 
        ///  解压文件 自动匹配 rar文件 和zip
        /// 

        /// 压缩文件目录
        /// 解压目录
        /// 解压密码
        /// 
        public bool Unpack(string FileToUp string edFolder string password = ““)
        {
            bool flag = false;

            //获取文件的真正类型
            string f = FileType.GetFileType(FileToUp);


            try
            {

                switch (f)
                {
                    case “zip“:
                        flag = UnZip(FileToUp edFolder password = ““);
                        break;
                    case “rar“:
                        
                        break;
                }

            }
            catch (Exception)
            {

            }
            finally
            {
                //结束的委托
                if (overD != null)
                    overD();
            }


            return flag;
        }

        
        #region 解压文件
        /// 
        /// 解压文件
        /// 

        /// 待解压的文件
        /// 指定解压目标目录
        private bool UnZip(string FileToUpZip string ZipedFolder string password = ““)
        {
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();

            bool blResult;//表示解压是否成功的返回结果

            if (!File.Exists(FileToUpZip))
            {
                blResult = false;
                return blResult;
            }
            if (!Directory.Exists(ZipedFolder))
            {
                Directory.CreateDirectory(ZipedFolder);
            }
            FileStream OpenStream = null;
            Ionic.Zip.ZipFile zipFile = null;
            FileStream streamWriter = null;

            double per = 0; //当前百分比
            double currentNum = 0; //当前解压了的大小
            double count = 0; //解压后的总大小
            try
            {

                OpenStream = File.OpenRead(FileToUpZip);


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-01-12 10:30  compressDemo\
     目录           0  2017-01-12 11:01  compressDemo\compressDemo\
     文件         187  2017-01-12 10:30  compressDemo\compressDemo\App.config
     文件        2675  2017-01-12 10:59  compressDemo\compressDemo\FileType.cs
     文件        4159  2017-01-12 10:53  compressDemo\compressDemo\Form1.Designer.cs
     文件        6260  2017-01-12 11:01  compressDemo\compressDemo\Form1.cs
     文件        5817  2017-01-12 10:53  compressDemo\compressDemo\Form1.resx
     文件         524  2017-01-12 10:30  compressDemo\compressDemo\Program.cs
     目录           0  2017-01-12 10:30  compressDemo\compressDemo\Properties\
     文件        1366  2017-01-12 10:30  compressDemo\compressDemo\Properties\AssemblyInfo.cs
     文件        2876  2017-01-12 10:30  compressDemo\compressDemo\Properties\Resources.Designer.cs
     文件        5612  2017-01-12 10:30  compressDemo\compressDemo\Properties\Resources.resx
     文件        1099  2017-01-12 10:30  compressDemo\compressDemo\Properties\Settings.Designer.cs
     文件         249  2017-01-12 10:30  compressDemo\compressDemo\Properties\Settings.settings
     目录           0  2017-01-12 10:30  compressDemo\compressDemo\bin\
     目录           0  2017-01-12 11:01  compressDemo\compressDemo\bin\Debug\
     文件      462336  2011-08-07 10:01  compressDemo\compressDemo\bin\Debug\Ionic.Zip.dll
     文件       15360  2017-01-12 11:01  compressDemo\compressDemo\bin\Debug\compressDemo.exe
     文件         187  2017-01-12 10:30  compressDemo\compressDemo\bin\Debug\compressDemo.exe.config
     文件       38400  2017-01-12 11:01  compressDemo\compressDemo\bin\Debug\compressDemo.pdb
     文件       23168  2017-01-12 11:01  compressDemo\compressDemo\bin\Debug\compressDemo.vshost.exe
     文件         187  2017-01-12 10:30  compressDemo\compressDemo\bin\Debug\compressDemo.vshost.exe.config
     文件         490  2013-03-18 17:00  compressDemo\compressDemo\bin\Debug\compressDemo.vshost.exe.manifest
     文件        6629  2017-01-12 11:00  compressDemo\compressDemo\compress.cs
     文件        3983  2017-01-12 11:00  compressDemo\compressDemo\compressDemo.csproj
     目录           0  2017-01-12 10:33  compressDemo\compressDemo\dll\
     文件      462336  2011-08-07 10:01  compressDemo\compressDemo\dll\Ionic.Zip.dll
     目录           0  2017-01-12 10:30  compressDemo\compressDemo\obj\
     目录           0  2017-01-12 11:01  compressDemo\compressDemo\obj\Debug\
     文件         865  2017-01-12 10:30  compressDemo\compressDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7111  2017-01-12 10:59  compressDemo\compressDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此处省略13个文件信息

评论

共有 条评论