如何将整个文件夹添加到zip存档中

时间:2013-01-23 17:48:50

标签: c# dotnetzip

我尝试了zip.AddDirectory,但我无法弄清楚如何将 整个文件夹 导入到存档中(使用DotNetZip )。

NOT 想要这个:

enter image description here

但是这个:

enter image description here

1 个答案:

答案 0 :(得分:4)

来自DotNetZip source code examples

重新映射目录。压缩一组文件和目录,并将它们重新映射到zip文件中的不同目录层次结构中:

using (ZipFile zip = new ZipFile())
{
    // files in the filesystem like MyDocuments\ProjectX\File1.txt , will be stored in the zip archive as  backup\File1.txt
    zip.AddDirectory(@"MyDocuments\ProjectX", "backup");
    // files in the filesystem like MyMusic\Santana\OyeComoVa.mp3, will be stored in the zip archive as  tunes\Santana\OyeComoVa.mp3
    zip.AddDirectory("MyMusic", "tunes");
    // The Readme.txt file in the filesystem will be stored in the zip archive as documents\Readme.txt
    zip.AddDirectory("Readme.txt", "documents");
    zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G") ; 
    zip.Save(ZipFileToCreate);
}
相关问题