• c#压缩文件和批量压缩文件


    引用ICSharpCode.SharpZipLib.dll

     1 /// <summary>
     2         /// 压缩文件
     3         /// </summary>
     4         /// <param name="dirpath">压缩后存放地址</param>
     5         /// <param name="filepath">需要压缩文件的全路径</param>
     6         public static void ZipFile(string dirpath,string filepath)
     7         {
     8 
     9             string filefullname = Path.GetFileName(filepath);//获取需要压缩的文件的全名称
    10             string filename = Path.GetFileNameWithoutExtension(filepath);//获取需要压缩的文件不含扩展名的名称
    11             FastZip fastZip = new FastZip();//创建压缩对象
    12             fastZip.CreateZip(dirpath+"\"+ filename+".zip", dirpath, false, filefullname);//创建压缩文件
    13                 
    14         }
    15        /// <summary>
    16        /// 批量压缩文件
    17        /// </summary>
    18        /// <param name="dirpath">需要批量压缩的文件夹路径</param>
    19         public static void ZipDirFile(string dirpath)
    20         {
    21             DirectoryInfo dir = new DirectoryInfo(dirpath);//创建文件夹对象
    22             FileSystemInfo[] fielinfo= dir.GetFileSystemInfos();//获取目录下所有文件
    23             foreach (FileSystemInfo item in fielinfo)
    24             {
    25                 if (item is DirectoryInfo)//判断是否时文件夹
    26                 {
    27                     ZipDirFile(item.FullName);//是文件夹就递归调用自己
    28                 }
    29                 else
    30                 {
    31                     ZipFile(dirpath, item.FullName);//是文件就压缩
    32                 }
    33             }
    34         }
  • 相关阅读:
    linux抓包命令tcpdump
    Linux ssh配置详解
    吞吐量(TPS)、QPS、并发数、响应时间(RT)概念
    Python装饰器详解
    centos7 安装redis
    C# 操作Exchange 的powershell以实现邮件撤回
    C# 委托的理解和案例
    IIS10 http重定向https
    程序员修炼之道 | 不要让你的代码走上渡渡鸟的灭绝之路
    离子烫攻略
  • 原文地址:https://www.cnblogs.com/leizhui/p/11965458.html
Copyright © 2020-2023  润新知