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

温州哪家做网站百度云网站入口

温州哪家做网站,百度云网站入口,网站制作公司北京,装修网站加盟骗局压缩包格式,本文主要用于说明如何使用代码 文件或文件夹压缩为 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.zhongyajixie.com/news/25080.html

相关文章:

  • 网站制作价格情况百度页面
  • 虎门网站建设推广论坛seo招聘
  • 2345浏览器免费版百度seo工作室
  • 免费生成网页的网站企业宣传推广
  • 山东企业网站建设百度咨询电话 人工客服
  • 网站开发流程步骤关键词优化课程
  • 自己做的网站打不开了seo营销方案
  • 网上那个网站做席子批发谷歌搜索引擎免费入口 台湾
  • 利用已有网站 制作悟空建站seo服务
  • 网站公安局备案 所需要的材料查询网站流量的网址
  • 做网站为职业生存不下去seo基础入门免费教程
  • 网站推广打包关键词排名优化系统
  • 广水网站建设北京网站优化公司哪家好
  • 如何做的网站手机可以用南京seo网站优化
  • 产教融合信息门户网站建设方案企业网页设计与推广
  • 一站式网站上海网站排名推广
  • 网站制作案例市场搜索百度网址网页
  • 做线上交互的网站网站流量统计分析工具
  • 做网站最主要上海百度竞价
  • 郑州做网站的多不多搜索引擎优化报告
  • 网站加入联盟哪些网站是营销型网站
  • 外贸网站如何建站近10天的时事新闻
  • 做网站的步骤的文本百度竞价入口
  • 北京的网站建设公司seo关键词排名优化费用
  • wordpress收录温州seo教程
  • 南宫建设局网站首页今日新闻 最新消息 大事
  • 住房和城乡建设岗位评定网站站长工具樱花
  • 模仿网站怎么防止侵权临沂google推广
  • 淘宝客建网站北京seo优化服务
  • 拉萨做网站公司百度地图人工客服电话