C#中压缩工具整理之一 : DotNetZipLib

/****************by Jiangong SUN***************/

整整两天半天的工作让我对在C#中的两个优质的压缩解压缩工具DotNetZipLib和SharpZipLib有了比较不错的了解. 1, DotNetZipLib //解压zip中指定的多个文件 private static void Extract(){ var path = ConfigurationManager.AppSettings["path"]; var rootDirectory = new DirectoryInfo(path); if (rootDirectory.Exists) { List<string> listFiles = new List<string>(); foreach (var fileInfo in rootDirectory.GetFiles()) listFiles.Add(fileInfo.FullName); foreach (string item in listFiles) { string unpackZipFile = item; var paths = item.Split('//'); var folderName = paths[paths.Length - 1].Replace(".zip", ""); var brandCode = folderName.Substring(0, 2); var cultureCode = folderName.Substring(3, 5); var countryName = folderName.Substring(6, 2); string unpackDirectory = path + "//Extracted//" + folderName; //DotNetZipLib using (ZipFile zipFiles = ZipFile.Read(unpackZipFile)) { var zipEntry = zipFiles.SelectEntries("filename1*").FirstOrDefault(); if (zipEntry != null) zipEntry.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently); var zipEntry = zipFiles.SelectEntries("filename2*").FirstOrDefault(); if (zipEntry != null) zipEntry.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently); } } } } //解压某文件夹下所有zip文件的所有内容 public static void extractFilesFromZip(string path) { List<string> listFiles = new List<string>(); DirectoryInfo dirs = new DirectoryInfo(path); foreach (var fileInfo in dirs.GetFiles()) listFiles.Add(fileInfo.FullName); foreach (string item in listFiles) { string zipToUnpack = item; Console.WriteLine(zipToUnpack); string unpackDirectory = "C://SHARED//ROOT AO FILES"; using (ZipFile zip1 = ZipFile.Read(zipToUnpack)) { foreach (ZipEntry e in zip1) { e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently); } } } } static void Main(string[] args) { extractFilesFromZip("C://SHARED//ROOT AO FILES"); } }

 

Reference:

http://dotnetslackers.com/_NET/re-58114_Working_with_Zip_files_Part_I_Uploading_and_Expandning.aspx
http://www.blogjava.net/bacoo/archive/2007/12/29/171617.html
http://stackoverflow.com/questions/328343/using-sharpziplib-to-unzip-specific-files
http://www.answerspice.com/c119/1699274/using-sharpziplib-to-unzip-specific-files
http://www.eggheadcafe.com/tutorials/aspnet/9ce6c242-c14c-4969-9251-af95e4cf320f/zip--unzip-folders-and-f.aspx
http://www.hdut.com/code/C_JieYaHuoYaSuoWenJianJia.htm
http://www.airhh.com/index.php/archives/14

你可能感兴趣的:(String,String,C#,C#,Path,Path,Path,工具,reference,reference)