/// <summary>
/// 压缩zip
/// </summary>
/// <param name="fileToZips">文件路径集合</param>
/// <param name="zipedFile">想要压成zip的文件名</param>
public static void ZipOld(string[] fileToZips, string zipedFile)
{
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipedFile, Encoding.UTF8))
{
List <string> pathlist = new List <string>();
foreach (string fileToZip in fileToZips)
{
if (System.IO.File.Exists(fileToZip))
{
using (FileStream fs = new FileStream(fileToZip, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string fileName = fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1);
string filePath = fileToZip.Substring(0, fileToZip.LastIndexOf("\\"));
if (!pathlist.Exists(x => x.Equals(filePath)))
{
pathlist.Add(filePath);
zip.AddDirectoryByName(filePath);
}
zip.AddFile(fileToZip, filePath);
}
}
if (System.IO.Directory.Exists(fileToZip))
{
string filePath = fileToZip.Substring(fileToZip.IndexOf("\\") + 1);
zip.AddDirectoryByName(filePath);
zip.AddDirectory(fileToZip, filePath);
//ZipFileDictory(fileToZip, "", zip);
}
}
zip.Save();
}
}