参考:https://blog.csdn.net/zhaotianff/article/details/141156035
using System.IO.Compression; namespace XCG.Commons { public class ZipUtil { /// <summary> /// 压缩zip /// </summary> /// <param name="inputFolder">要压缩的目录</param> /// <param name="destinationZipPath">压缩后zip存放地址</param> public static void CreateZip(string inputFolder, string destinationZipPath) { if (Directory.Exists(inputFolder)) { ZipFile.CreateFromDirectory(inputFolder, destinationZipPath); } } /// <summary> /// 解压zip /// </summary> /// <param name="zipFilePath">zip压缩包地址</param> /// <param name="extractPath">解压到此目录</param> public static void ExtractZip(string zipFilePath, string extractPath) { if (File.Exists(zipFilePath)) { ZipFile.ExtractToDirectory(zipFilePath, extractPath); } } } }
测试代码
[HttpGet] public void GenRarZip() { //获取项目路径 var webRootPath = this._env.ContentRootPath; var fileDir = $"UploadFile\\123\\"; var dirPath = Path.Combine(webRootPath, fileDir); //压缩包存放地址 var tarDir = $"ZipFile\\123.zip"; var tarPath = Path.Combine(webRootPath, tarDir); ZipUtil.CreateZip(dirPath, tarPath); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
2022-10-14 .net maui拨打电话
2015-10-14 sql标量值函数,将汉字转化为拼音,无音标