i imagine this is very simple but i can find nothing in the DotNetZip examples or documentation to help me. I need to add a folder to a zip that contains both folders and files, i need to maintain the folders rather than only zipping their files but using the following it always strips away the folders:

 using (ZipFile zip = new ZipFile())
                {
                    string[] files = Directory.GetFiles(@TempLoc);
                    string[] folders = Directory.GetDirectories(@TempLoc);
                    zip.AddFiles(files, "Traces");

                    foreach (string fol in folders)
                    {
                        zip.AddDirectory(fol, "Traces");
                    }

                    zip.Comment = "These traces were gathered " + System.DateTime.Now.ToString("G");
                    zip.Save(arcTraceLoc + userName.Text + "-Logs.zip");
                }

I'm using the loop as i could not find a function for folders similar to 'AddFiles' in DotNetZip.

Thanks.

有帮助吗?

解决方案

I think this is what you need:

  bool recurseDirectories = true;
  using (ZipFile zip = new ZipFile())
  {
    zip.AddSelectedFiles("*", @TempLoc, string.Empty, recurseDirectories);
    zip.Save(ZipFileToCreate);
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top