当前位置: 首页 > news >正文

南阳市做网站景点旅游网站开发与设计

南阳市做网站,景点旅游网站开发与设计,安阳seo优化,建立网站所需费用项目清单压缩包格式,本文主要用于说明如何使用代码 文件或文件夹压缩为 zip压缩包及其解压操作, 下面分两个版本进行实现 1.简单版本 bool DoCompressDirectoryInfo(string folderPath){try{var zipFilePath $"{folderPath}.zip";var directoryInfo …

压缩包格式,本文主要用于说明如何使用代码 文件或文件夹压缩为 zip压缩包及其解压操作,
下面分两个版本进行实现

1.简单版本

   bool DoCompressDirectoryInfo(string folderPath){try{var zipFilePath = $"{folderPath}.zip";var directoryInfo = new DirectoryInfo(zipFilePath);if (directoryInfo.Exists){directoryInfo.Delete();}if (directoryInfo.Parent != null){directoryInfo = directoryInfo.Parent;}System.IO.Compression.ZipFile.CreateFromDirectory(folderPath, zipFilePath, CompressionLevel.Optimal, false);return true;}catch (Exception ex){_logger.LogError(ex, $"压缩文件失败,{folderPath}!");return false;}}

2.第二种复杂版本

帮助类

class FolderCompressor
{public stati  bool DoCompressDirectoryInfo(string folderPath){try{var zipFilePath = $"{folderPath}.zip";FolderCompressor.CompressFolder(folderPath, zipFilePath);return true;}catch (Exception ex){_logger.LogError(ex, $"压缩文件失败,{folderPath}!");return false;}}public static void CompressFolder(string sourceFolderPath, string destinationZipFilePath){using FileStream zipToOpen = new FileStream(destinationZipFilePath, FileMode.Create);using ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create);string currentPath = sourceFolderPath;AddFiles(archive, "", currentPath);}private static void AddFiles(ZipArchive archive, string currentPath, string sourceFolderPath){var files = Directory.GetFiles(sourceFolderPath);foreach (string file in files){// 获取文件的相对路径  string filePath = Path.GetFullPath(file);string relativePath = filePath.Substring(sourceFolderPath.Length).TrimStart(Path.DirectorySeparatorChar);// 将文件添加到ZIP存档  var readOnlyEntry = archive.CreateEntry(Path.Combine(currentPath, relativePath));using var fileToCompress = File.OpenRead(file);using var entryStream = readOnlyEntry.Open();fileToCompress.CopyTo(entryStream);}// 递归处理子文件夹  string[] directories = Directory.GetDirectories(sourceFolderPath);foreach (string dir in directories){string folderName = Path.GetFileName(dir);AddFiles(archive, Path.Combine(currentPath, folderName), dir);}}
}

调用时候最好用 DoCompressDirectoryInfo方法

http://www.yayakq.cn/news/454688/

相关文章:

  • 网站建设域名怎么选择网站建设适应全屏如何自动
  • 网站开发人员绩效考核wordpress插件在哪
  • 随州做网站的公司网页设计实训报告总结免费
  • 为什么做儿童音乐网站wordpress页脚页脚插件
  • 好的app设计网站有哪些长春网站开发培训
  • 网站建设的卖点国内wordpress博客
  • 哪里有配音的网站七牛 wordpress 视频处理
  • 宝安区住房和建设局网站980网站
  • 京网站建设首选白龙马扬州百姓网免费发布信息网
  • asp网站建设运用的技术千锋教育
  • 重庆制作网站公司做网站卖什么产品利润高
  • 东莞我的网站建设安福相册网站怎么做的
  • 做网站的流程前端做什么如何腾讯云二级域名做网站
  • 公司网站实名制杭州官网
  • 高端网站开发怎么选郑州网络营销与网站推广
  • 上海网站建设 微信开发公司哪家好查询域名后缀网站
  • 网站改版 百度影响做网站要钱吗
  • 北京个人网站公司从化门户网站建设
  • 学平面设计的网站白云网站建设价格
  • 服装网站建设方案ppt深圳定制网站制作费用
  • 哪些做网站的公司wordpress 内容编辑器
  • 加拿大28网站开发网站设计制作用软件
  • 织梦dedecms蓝色培训机构模板教育学校学院整站php网站源码免费网页小游戏在线玩
  • 建网站需要什么软件wordpress tag链接优化
  • 大连网络运营郑州网站建设优化
  • 网站搭建交流群中秋贺卡手工制作图片 简单
  • 提示网站有风险网页建设哪家好
  • 北京网站开发怎么样企业网站建设英文
  • 湖北网站建设哪里有.net 网站域账号自动验证码
  • 邯郸市做网站建设济南百度代理