Creating a zip saves entire pathname?

Coordinator
May 15, 2008 at 4:34 PM

Someone wrote:
I would like to create a zip with some files, and a couple of folders and sub folders, but when I do this, it is copying the entire directory breakdown. Only the files in these folders are copied, but it includes the entire directory location in the zip... How can I fix this?

Here is the code I am using:

try
{
  using (ZipFile zip = new ZipFile(DatabaseCBFilePathTB1.Text + @"\Backup.zip"))
  {
    zip.AddFile(Environment.CurrentDirectory + @"\DB.accdb");
    zip.AddDirectory(Environment.CurrentDirectory + @"\Files");
    zip.Save();
  }
}

Any help and information is greatly appreciated.

Thanks Again,

Coordinator
May 15, 2008 at 4:38 PM

Couple ways to do this

  1. There's an override on the AddFile() method that allows you to explicitly specify the directory within the zip archive, to use for that entry.  Likewise for AddDirectory().  If you want a flat directory space, then you can specify "" (empty string, not null/nothing) for that parameter.  Check the doc.
  2. change to the directory that contains the file using 

                System.IO.Directory.SetCurrentDirectory(whatever);

     , then call AddFile() with an unqualified pathname.