List Directories

Jan 21, 2009 at 2:15 PM
Hi,

Is there any way to list the directories conatined in the zip file rather than every file?

Thanks
Coordinator
Jan 21, 2009 at 4:40 PM
Use the IsDirectory property on the ZipEntry. For illustration, you could do something like this:
List<string>  GetContainedDirectories(string zipfile)
{
  List<string> list = new List<string>();
  using (ZipFile zip = ZipFile.Read("MyZipFile.zip")) 
  {
    foreach (ZipEntry e in zip) 
    {
      if (e.IsDirectory) 
         list.Add(e.FileName); 
    }
  }
  return list;
}

If you prefer, you could start with the above, and using the .NET 3.5 capability, with slight mods, add this method as an extension method to the ZipFile class. See the wikipedia article for an overview on the how and why of extension methods.