public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> test = new List<string>()
{
"2013-10-09.txt",
"2013-10-10.txt",
"2013-10-11.txt"
};
ZipFiles(test,Request.PhysicalApplicationPath + "test2\\aaa1.zip");
}
public static void ZipFiles(List<string> paths, string savePath)
{
using (ZipFile zip = new ZipFile(savePath))
{
Directory.SetCurrentDirectory(HttpContext.Current.Request.PhysicalApplicationPath + "test\\");// 临时切换到当前目录
foreach (string filePath in paths)
{
zip.AddFile(filePath);
}
Directory.SetCurrentDirectory(Directory.GetCurrentDirectory()); // 恢复当前目录
zip.Save();
}
}
}压缩文件(压缩路径只包含文件)
批量文件压缩与Zip文件操作
最新推荐文章于 2024-03-05 16:16:54 发布
本文介绍如何使用C#编程语言实现多个文件的批量压缩为Zip文件,并详细阐述了Zip文件的基本操作流程,包括创建Zip文件、添加文件以及保存Zip文件的过程。
1273

被折叠的 条评论
为什么被折叠?



