简体   繁体   English

使用Ionic Zip库压缩多个目录

[英]Zip multiple directories Using Ionic Zip Library

I'm trying to zip several folders with their content into one zip file using Ionic Zip Library. 我正在尝试使用Ionic Zip Library将多个文件夹及其内容压缩到一个zip文件中。 The code below did created a zip file, however the folders were not added to it. 下面的代码确实创建了一个zip文件,但是未将文件夹添加到其中。

private void ZipFolder(List <string> folders, string pathToSaveZipFile)
    {
        using (ZipFile zip = new ZipFile())
        {
            foreach (string itrFolder in folders)
            {
                zip.AddDirectory(itrFolder);
            }
            zip.Save(pathToSaveZipFile);
        }
    }

Thank you 谢谢

AddDirectory(string) adds the files to the root, you need to use AddDirectory(string)将文件添加到根目录,您需要使用

zip.AddDirectory(itrFolder,  new DirectoryInfo(itrFolder).Name);

The second argument specifies the folder name within the ZIP. 第二个参数指定ZIP中的文件夹名称。

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

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