码迷,mamicode.com
首页 > 其他好文 > 详细

ZIP文件解压

时间:2015-07-23 21:27:58      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

public class DZip
{
/// <summary>
/// 压缩为ZIP文件
/// </summary>
public void Zip(string directory,string fileName)
{
//using (var archive = ZipArchive.Create())
//{
// archive.AddAllFromDirectory(@"C:\\source");
// archive.SaveTo(@"C:\\new.zip", CompressionType.GZip);
//}
using (var archive = ZipArchive.Create())
{
archive.AddAllFromDirectory(directory);
archive.SaveTo(fileName, CompressionType.BZip2);
}

//using (var zip = File.OpenWrite(fileName))
//using (var zipWriter = WriterFactory.Open(File.Open(fileName,FileMode.Append),ArchiveType.Zip,CompressionType.BZip2))
//{
// string[] filesList = Directory.GetFiles(directory);
// foreach (var filePath in filesList)
// {
// zipWriter.Write(Path.GetFileName(filePath), filePath);
// }
//}
}

/// <summary>
/// ZIP文件解压
/// </summary>
/// <param name="pathZip">zip文件所在的路径</param>
/// <param name="toDirectory">要解压到的文件夹</param>
public void UnZip(string pathZip, string toDirectory)
{
var archive = ArchiveFactory.Open(pathZip);
foreach (var entry in archive.Entries)
{
if (!entry.IsDirectory)
{
entry.WriteToDirectory(toDirectory, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
}
}
}

ZIP文件解压

标签:

原文地址:http://www.cnblogs.com/pengde/p/4671734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!