如何压缩文件夹中的所有文件 [英] How to zip all files in folder

查看:53
本文介绍了如何压缩文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹 "D:\folder",在这个文件夹中我有 10 个文件需要压缩到一个新的存档 "D:\folder.zip".

I have a folder "D:\folder" and in this folder I have 10 files that I need to zip into a new archive "D:\folder.zip".

目前我正在使用 ICSharpCode.SharpZipLib 但这不是强制性要求,因此其他解决方案也是可以接受的.

Currently I'm using ICSharpCode.SharpZipLib but this is not a mandatory requirement, so other solutions are acceptable.

我面临的问题是,当我尝试执行方法 FileStream fs = File.OpenRead(@"D:\folder") 时,由于访问指定的路径.

The problem I'm facing is that when I try to execute the method FileStream fs = File.OpenRead(@"D:\folder") I get an error because of access to the specifided path.

如何以简单的方式压缩这些文件?

How can I zip these files in a simple way?

推荐答案

DotNetZip 比 SharpZipLib 更容易使用,压缩示例文件夹中的所有文件:

DotNetZip is much easier to use than SharpZipLib, example of zipping all files in folder :

  using (ZipFile zip = new ZipFile())
  {
    zip.AddDirectory(@"MyDocuments\ProjectX", "ProjectX");
    zip.Save(zipFileToCreate);
  }

这是这个页面的一个例子:

This is a an example from this page :

http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle=示例

这篇关于如何压缩文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆