37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using ICSharpCode.SharpZipLib.Zip;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCode.Project.Infrastructure.Common
|
|
{
|
|
public class ZipHelper
|
|
{
|
|
#region Zip(根据传递的路径压缩成一个文件)
|
|
/// <summary>
|
|
/// 根据传递的路径压缩成一个文件
|
|
/// </summary>
|
|
/// <param name="filePaths"></param>
|
|
/// <param name="savePath"></param>
|
|
public static void Zip(List<string> filePaths, string savePath)
|
|
{
|
|
if (filePaths == null || filePaths.Count == 0) { }
|
|
using (ZipFile zip = ZipFile.Create(savePath))
|
|
{
|
|
zip.BeginUpdate();
|
|
|
|
foreach (var path in filePaths)
|
|
{
|
|
var fileName = Path.GetFileName(path);
|
|
zip.Add(path, fileName);
|
|
}
|
|
zip.CommitUpdate();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|