c # compressed files and batch file compression

Reference ICSharpCode.SharpZipLib.dll

 

. 1  ///  <Summary> 
2          /// archive
 . 3          ///  </ Summary> 
. 4          ///  <param name = "dirpath is"> storing the compressed address </ param> 
. 5          ///  <param name = " filepath "> need to compress the file full path </ param> 
. 6          public  static  void the ZipFile ( String dirpath is, String filepath)
 . 7          {
 . 8  
. 9              String filefullname = Path.GetFileName (filepath); // full name acquisition needs to be compressed files 
10              String filename = Path.GetFileNameWithoutExtension (filepath); //The need to obtain the name of the compressed file name without extension 
11              FastZip fastZip = new new FastZip (); // create a compressed objects 
12              fastZip.CreateZip (dirpath + " \\ " + filename + " .zip " , dirpath, false , filefullname); / / creating an archive 
13 is                  
14          }
 15         ///  <Summary> 
16         /// batch archive
 . 17         ///  </ Summary> 
18 is         ///  <param name = "dirpath is"> need to batch compressed folder path </ param> 
19          public  static  voidZipDirFile ( String dirpath is)
 20 is          {
 21 is              the DirectoryInfo the dir = new new the DirectoryInfo (dirpath is); // Create a folder object 
22 is              the FileSystemInfo [] = fielinfo dir.GetFileSystemInfos (); // get all files in the directory 
23 is              the foreach (the FileSystemInfo Item in fielinfo)
 24-              {
 25                  iF (Item iS DirectoryInfo) // determine whether folder 
26                  {
 27                      ZipDirFile (item.FullName); // is the folder that calls itself recursively 
28                 }
 29                  the else 
30                  {
 31 is                      the ZipFile (dirpath is, item.FullName); // file compresses 
32                  }
 33              }
 34          }

 

Guess you like

Origin www.cnblogs.com/leizhui/p/11965458.html