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

公司网站如何被百度快照定制微信

公司网站如何被百度快照,定制微信,如何自主建设企业网站,双流区规划建设局官方网站.NET C# 将文件夹压缩至 zip 文章目录 .NET C# 将文件夹压缩至 zip1 使用 System.IO.Compression1.1 环境1.2 压缩文件夹1.2.1 简单压缩1.2.2 复杂压缩 1.3 解压缩1.3.1 简单解压缩1.3.2 复杂解压缩 2 使用 SharpZipLib2.1 环境2.2 压缩文件夹2.3 解压缩 3 压缩效果简单测试 1 ….NET C# 将文件夹压缩至 zip 文章目录 .NET C# 将文件夹压缩至 zip1 使用 System.IO.Compression1.1 环境1.2 压缩文件夹1.2.1 简单压缩1.2.2 复杂压缩 1.3 解压缩1.3.1 简单解压缩1.3.2 复杂解压缩 2 使用 SharpZipLib2.1 环境2.2 压缩文件夹2.3 解压缩 3 压缩效果简单测试 1 使用 System.IO.Compression 1.1 环境 .NET 6 1.2 压缩文件夹 1.2.1 简单压缩 using System.IO.Compression;string sourceDirectory C:\path\to\your\folder; // 需要压缩的文件夹路径 string destinationZipFilePath C:\path\to\your\output.zip; // 生成的zip文件路径 // 压缩文件夹 ZipFile.CreateFromDirectory(sourceDirectory, destinationZipFilePath);注意事项 请确保路径正确并且具有对该路径的读写权限。如果目标zip文件已存在该方法将覆盖该文件。如果你想避免覆盖可以在压缩前检查文件是否存在并进行相应处理。 1.2.2 复杂压缩 如果你需要更复杂的压缩选项比如排除某些文件或文件夹可以使用ZipArchive类来进行更细粒度的控制。 using System.IO.Compression;string sourceDirectory C:\path\to\your\folder; string destinationZipFilePath C:\path\to\your\output.zip;using (FileStream zipToOpen new FileStream(destinationZipFilePath, FileMode.Create)) {using (ZipArchive archive new ZipArchive(zipToOpen, ZipArchiveMode.Create)){DirectoryInfo directorySelected new DirectoryInfo(sourceDirectory);foreach (FileInfo fileToCompress in directorySelected.GetFiles()){// 过滤特定文件例如排除所有.txt文件if (fileToCompress.Extension .txt)continue;archive.CreateEntryFromFile(fileToCompress.FullName, fileToCompress.Name);}} }1.3 解压缩 1.3.1 简单解压缩 using System.IO.Compression;string sourceZipFilePath C:\path\to\your\archive.zip; // 需要解压缩的zip文件路径 string destinationDirectory C:\path\to\your\output\folder; // 解压缩到的目标文件夹路径 // 解压缩zip文件 ZipFile.ExtractToDirectory(sourceZipFilePath, destinationDirectory);注意事项 请确保路径正确并且具有对该路径的读写权限。如果目标文件夹已存在且包含与zip文件中相同名称的文件该方法将抛出异常。如果你想避免此问题可以在解压缩前检查文件夹是否存在并进行相应处理。 1.3.2 复杂解压缩 using System.IO.Compression;string sourceZipFilePath C:\path\to\your\archive.zip; string destinationDirectory C:\path\to\your\output\folder;using (ZipArchive archive ZipFile.OpenRead(sourceZipFilePath)) {foreach (ZipArchiveEntry entry in archive.Entries){// 解压缩所有文件到目标文件夹string destinationPath Path.Combine(destinationDirectory, entry.FullName);// 如果条目是目录则创建目录if (entry.Name ){Directory.CreateDirectory(destinationPath);}else{// 创建包含该条目的目录Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));// 解压缩文件entry.ExtractToFile(destinationPath, overwrite: true);}} }2 使用 SharpZipLib 2.1 环境 .NET 6SharpZipLib 1.4.2 2.2 压缩文件夹 using System; using System.IO; using ICSharpCode.SharpZipLib.Zip;class Program {static void Main(){string sourceDirectory C:\path\to\your\folder; // 需要压缩的文件夹路径string destinationZipFilePath C:\path\to\your\output.zip; // 生成的zip文件路径// 压缩文件夹CompressFolder(sourceDirectory, destinationZipFilePath);Console.WriteLine(文件夹已成功压缩到 destinationZipFilePath);}static void CompressFolder(string sourceDir, string zipFilePath){// 创建目标zip文件using (FileStream fsOut File.Create(zipFilePath))using (ZipOutputStream zipStream new ZipOutputStream(fsOut)){zipStream.SetLevel(3); // 设置压缩级别0-9// 遍历源文件夹中的所有文件和目录int folderOffset sourceDir.Length (sourceDir.EndsWith(\\) ? 0 : 1);CompressDirectory(sourceDir, zipStream, folderOffset);}}static void CompressDirectory(string path, ZipOutputStream zipStream, int folderOffset){string[] files Directory.GetFiles(path);foreach (string filename in files){FileInfo fi new FileInfo(filename);string entryName filename.Substring(folderOffset); // 创建条目名entryName ZipEntry.CleanName(entryName); // 清理名称ZipEntry newEntry new ZipEntry(entryName);newEntry.DateTime fi.LastWriteTime; // 设置条目的日期时间newEntry.Size fi.Length; // 设置条目的大小zipStream.PutNextEntry(newEntry);// 写入文件内容byte[] buffer new byte[4096];using (FileStream streamReader File.OpenRead(filename)){StreamUtils.Copy(streamReader, zipStream, buffer);}zipStream.CloseEntry();}// 递归处理目录string[] folders Directory.GetDirectories(path);foreach (string folder in folders){CompressDirectory(folder, zipStream, folderOffset);}} }2.3 解压缩 using System; using System.IO; using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Zip;class Program {static void Main(){string sourceZipFilePath C:\path\to\your\archive.zip; // 需要解压缩的zip文件路径string destinationDirectory C:\path\to\your\output\folder; // 解压缩到的目标文件夹路径// 解压缩zip文件ExtractZipFile(sourceZipFilePath, destinationDirectory);Console.WriteLine(文件已成功解压缩到 destinationDirectory);}static void ExtractZipFile(string archiveFilenameIn, string outFolder){ZipFile zf null;try{FileStream fs File.OpenRead(archiveFilenameIn);zf new ZipFile(fs);foreach (ZipEntry zipEntry in zf){if (!zipEntry.IsFile){continue; // 忽略目录条目}string entryFileName zipEntry.Name;string fullZipToPath Path.Combine(outFolder, entryFileName);string directoryName Path.GetDirectoryName(fullZipToPath);// 创建目录if (directoryName.Length 0){Directory.CreateDirectory(directoryName);}byte[] buffer new byte[4096]; // 4K是推荐的缓冲区大小// 解压缩文件using (Stream zipStream zf.GetInputStream(zipEntry))using (FileStream streamWriter File.Create(fullZipToPath)){StreamUtils.Copy(zipStream, streamWriter, buffer);}}}finally{if (zf ! null){zf.IsStreamOwner true; // 使ZipFile也关闭文件流zf.Close();}}} }3 压缩效果简单测试 组件压缩等级耗时ms结果数据大小KBSystem.IO.Compression1242333601975358953543769137136351221SharpZipLibNoCompression8561046400Fastest11571373848Optimal18642353490SmallestSize85536351208
http://www.hkea.cn/news/14280795/

相关文章:

  • 银川网站建设一条龙某某网站安全建设方案
  • 网站自己推广怎么做煤炭建设行业协会网站
  • 怎样做网站变手机软件php模板网站
  • 嘉兴网站建设方案服务凡科如何开通网站建设
  • 网站设计 wordpress网站源码下载
  • 最好的科技资讯网站怎么用照片制作小视频
  • 商务网站开发流程有哪三个阶段app图标制作
  • 自建网站如何备案谷歌网站入口
  • 江北网站建设的技术用jsp做一网站的流程
  • 招聘网站设计师要求网站建设 千佳网络
  • dede关闭手机网站企业网站开发哪家好
  • 网站开发用什么框架好邯郸网站制作地方
  • 二级黄冈站wordpress文章推荐
  • 网页编程培训深圳网站seo哪家快
  • 天津工程建设协会网站一个公司的官网怎么做
  • 什么样的公司愿意做网站免费制作网页的网站
  • 小程序制作搭建东莞排名seo网站关键词优化
  • 怎么做网站的轮播图dw网站制作的源代码
  • 全国各城市感染高峰进度查询宁波网站建设seo
  • 竞价托管网站建设自己开网店没有货源怎么办
  • 三好街做网站公司网站制作长春
  • php响应式网站开发百度云外贸网站建设论坛
  • seo整站优化公司持续监控百度的链接
  • 厦网站建设培训学校wordpress简约博客主题
  • 威海 医院网站建设商品详情页设计模板
  • 响应式网站 价格产品推广计划
  • intitle 郑州网站建设网站开发和程序开发
  • 扬州网站商城建设价格信息免费发布平台
  • 中国建设银行手机网站下载安装用模板做网站需要懂代码吗
  • wordpress淘宝客网站模板网站建设价表模板