0

Is there anyway in Dot Net Zip that I can use to list all the names of files in a specific directory? For example, i can specify Directory1 and get File3 and File4 etc

ZipFile
-------

File1
File2
Directory1
     File3
     File4
Directory2
     File5
     File6

ZipFile object has only Entries, Entries Sorted, and Entries File Names...

Anyone?, Cheeso? :)

Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
  • Have you looked here? http://stackoverflow.com/questions/2324626/extract-a-zip-file-programmatically-by-dotnetzip-library – Edward Leno Aug 03 '10 at 23:01
  • Thank you Edward, but i simply want only the names of the files :) I think i might be able to do something by a lil of bit string manipulation. Folders finish with a "/" – Ranhiru Jude Cooray Aug 04 '10 at 02:53

1 Answers1

1

No, and yes. There is no EntriesInDirectory collection. However, it's a simple matter of string comparison to select entries that "belong" in a particular directory.

In LINQ it looks like this:

var selection = from e in zip.Entries 
    where e.FileName.StartsWith(directoryName)
    select e;

In a for loop, it looks like this:

var list = new List<ZipEntry>();
foreach (var e in zip.Entries) {
  if (e.FileName.StartsWith(directoryName)) {
    list.Add(e);
  }
}

EDIT

You may have to do conversions for case sensitivity. On Windows, case is not meaningful in file names.

Further Explanation: the zip format doesn't treat a directory entry in the zip file as a container. There is no container relationship between directory entries and file entries. The only way to tell if a file entry "belongs in" a particular directory is to examine the full name of the file entry. If the name of the entry starts with the name of the directory in question, then the entry is "in" the directory.

Cheeso
  • 189,189
  • 101
  • 473
  • 713