日期:2014-05-17 浏览次数:21218 次
/// <summary>
/// 使用isharpziplib压缩文件
/// </summary>
/// <param name="rootDir">需要打包文件的顶级目录(结尾不含//)</param>
/// <param name="fileList">打包的文件(夹)的全路径列表</param>
/// <param name="filePath">目标压缩文件</param>
/// <returns></returns>
public static void CompressFile(string topDirName, List<string> fileNamesToZip, string ZipedFileName)
{
List<string> fileList = new List<string>();
foreach (string ss in fileNamesToZip)
{
string filename = ss.Replace(topDirName, "");
if (FileHelper.IsDir(ss))
{
fileList.AddRange(GetFileAndDir(ss, topDirName));
}
else
{
fileList.Add(filename);
}
}
using (ZipOutputStream s = new ZipOutputStream(System.IO.File.Open(ZipedFileName, FileMode.Create)))
{
s.SetLevel(6);
foreach (string file in fileList)
{
if (FileHelper.IsDir(topDirName + file)) //如果是文件夹 folder
{
ZipEntry entry = new ZipEntry(file + "\\");
&n