繁体   English   中英

使用SharpZipLib打包空目录

[英]pack empty directory with SharpZipLib

我想打包使用SharpZipLib压缩一些文件夹。 示例结构

directory1:
    directory2:
         file1
    file2
    directory3:
        directory4:

当我使用c#代码从这里打包它:

http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx#Create_a_Zip_with_full_control_over_contents_0

我得到没有directory3directory4 zip存档。

我的问题是如何打包以获取带有directory3directory4存档。

您可以使程序将文件夹添加为条目。

在每个文件夹的循环中添加以下代码。

//Here we create a path for a new entry,
//but this time with the '\' in the end, its a folder
string sEntry = sFolder.Substring(iFolderOffset) + "\\";
sEntry = ZipEntry.CleanName(sEntry);
ZipEntry zeOutput = new ZipEntry(sEntry);
zsOutput.PutNextEntry(zeOutput);
zsOutput.CloseEntry();

我还没有测试解压缩。

 FastZip fastZip = new FastZip();

 fastZip.CreateEmptyDirectories = true;
 // Include all files by recursing through the directory structure
 bool recurse = true; 
 // Dont filter any files at all 
 string filter = null;
 fastZip.CreateZip("fileName.zip", @"C:\SourceDirectory", recurse, filter);

一个警告是它无法处理UTF-8文件名。

这是文档维基的链接:

http://wiki.sharpdevelop.net/SharpZipLib_FastZip.ashx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM