SharpZipLib - 添加文件夹/目录到一个zip压缩包 [英] SharpZipLib - adding folders/directories to a zip archive

查看:997
本文介绍了SharpZipLib - 添加文件夹/目录到一个zip压缩包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从例子中,我已经对如何解压缩zip文件相当把握好。

From examples, I've got a pretty good grasp over how to extract a zip file.

在几乎所有的例子中,识别时的ZipEntry的方法目录如下:

In nearly every example, the method of identifying when a ZipEntry is a directory is as follows

string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);

if (directoryName.Length > 0)
  Directory.CreateDirectory(Path.Combine(destinationDirectory, directoryName));                    

if (fileName != String.Empty)
{
  //read data and write to file
}

现在是细而所有(目录遇到,创建它),在提取的文件目录是可用的。

Now is is fine and all (directory encountered, create it), directory is available when the file is extracted.

我可以将文件添加到压缩罚款,但我怎么添加文件夹?我明白了,我会通过目录中循环,添加文件时遇到(及其ZipEntry.Name属性正确填充),但如何做我添加的ZipEntry到归档,并指示ZipOutputStream它是一个目录?

I can add files to a zip fine, but how do I add folders? I understand I'll be looping through the directories, adding the files encountered (and their ZipEntry.Name property is populated properly), but how do I add a ZipEntry to the archive and instruct the ZipOutputStream that it is a directory?

推荐答案

ZipFile.AddDirectory 你想要做什么。小样本代码这里

ZipFile.AddDirectory does what you want. Small sample code here.

这篇关于SharpZipLib - 添加文件夹/目录到一个zip压缩包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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