如何COM preSS目录成一个zip文件编程 [英] How to compress a directory into a zip file programmatically

查看:105
本文介绍了如何COM preSS目录成一个zip文件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想COM preSS它可以有任意数量的子目录成一个ZIP文件的完整目录。

I want to compress an entire directory which can have any number of subdirectories into a single ZIP file.

我能够融为一体preSS的单个文件到一个zip文件编程。

I am able to compress a single file into a zip file programmatically.

要融为一体preSS整个目录,我能想到的遍历每个子目录递归程序和COM presses吧。

To compress an entire directory, i can think of a recursive program that walks through each subdirectory and compresses it.

但没有任何简单的方法来COM preSS使用类似code,整个文件夹,而无需编写任何递归函数?

But Is there any simple way to compress the entire folder using the similar code, without having to write any recursive functions?

推荐答案

使用 DotNetZip ,有一个AddDirectory()方法那你想要做什么zip文件类:

Using DotNetZip, there's an AddDirectory() method on the ZipFile class that does what you want:

using (var zip = new Ionic.Zip.ZipFile())
{
    zip.AddDirectory("DirectoryOnDisk", "rootInZipFile");
    zip.Save("MyFile.zip");
}

这个例子,和许多人一样,都是<一href="http://dotnetzip.$c$cplex.com/wikipage?title=Examples&referringTitle=Documentation">available在codePLEX 。

This example, and many others, are available on codeplex.

这篇关于如何COM preSS目录成一个zip文件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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