如何COM preSS目录成一个zip文件编程文件、目录、COM、preSS

2023-09-04 00:08:33 作者:认识我别动

我想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");
}

这个例子,和许多人一样,都是available在codePLEX 。

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