⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zipdao.cs

📁 这是一款系统系统备份的软件
💻 CS
字号:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;

namespace ZipApp
{
    public class ZipDao
    {
        public string file;
        public ZipDao(string dir)
        {
            file = dir;
        }

        public void ZipFold()
        {
            //获得压缩的文件夹
            //压缩文件夹的名字
            string name = file + ".rar";
            //压缩文件的流对象
            // MessageBox.Show(name);
            ZipOutputStream output = new ZipOutputStream(File.Create(name));
            output.SetLevel(6);
            string[] dir = Directory.GetFiles(file);
            //存放文件数据
            Crc32 crc = new Crc32();
            foreach (string myFile in dir)
            {
                FileStream fs = new FileStream(myFile, FileMode.Open, FileAccess.Read);
                byte[] bt = new byte[fs.Length];
                fs.Read(bt, 0, bt.Length);
                //存储要压缩的文件
                ZipEntry entry = new ZipEntry(myFile);
                entry.Size = fs.Length;
                entry.DateTime = DateTime.Now;
                fs.Close();
                crc.Reset();  //清除crc内容
                crc.Update(bt);  //更新文件内容到crc中
                entry.Crc = crc.Value;   //将文件内容放到压缩文件中
                output.PutNextEntry(entry);
                //将数据写入压缩流中
                output.Write(bt, 0, bt.Length);
            }
            output.Close();
            MessageBox.Show("压缩成功");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -