zoukankan      html  css  js  c++  java
  • 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         }
  • 相关阅读:
    generator
    JS 中 apply 、call 、bind的详解
    前端面试题(24-js)
    JS原型链深入了解
    Java12新特性
    Java11-ZGC
    Java11新特性
    Java10新特性
    Java9新特性
    CF1385E【Directing Edges】 (拓扑排序)
  • 原文地址:https://www.cnblogs.com/leizhui/p/11965458.html
Copyright © 2011-2022 走看看