Ionic.FileSelector.SelectEntries() can't return child folder entries?

Oct 11, 2010 at 7:43 PM
Edited Oct 11, 2010 at 9:34 PM

If i just do

ICollection<ZipEntry> results = selector.SelectEntries(zip);

I get all entries in the zip even entries that represent empty folders.  Seems to me it's the equivalent of specifying a starting path of "\\" or root. 

But if I try to retrieve entries that represent empty folders _starting from a certain path in the archive_  then it doesn't work.  It works for *.* and returning file entries, but not directory entries.  This seems like a bug to me.


If I  try something like

ICollection<ZipEntry> results = selector.SelectEntries(zip, "vehicles\\")

where sub folder entities I expect to get back are

vehicles\\cars

vehicles\\airplanes

vehicles\\trucks

vehicles\\trains

 

But none of the above sub entries are returned.

Mike

 

 

Oct 11, 2010 at 8:17 PM
Edited Oct 11, 2010 at 9:42 PM

I peeked at the code inside FileSelector.SelectEntries  and i see why it doesnt work.

instead ead of searching for the exact dir match you can just

 

foreach (entry in zip.Entries)

{

    string entryDir = Path.GetDirectoryName(entry.FileName);  // let's say entry.FileName =  "vehicles/cars/"  then this will result in entryDir = "vehicles\\cars"

    if (entryDir != startPath && startPath == Path.GetDirectoryName (entryDir))  // second call of GetDirectoryName on entryDir strips off another dir layer so now we compare with startPath to know if this is a first level child under the startpath
         results.Add(entry);

}

Oct 14, 2010 at 4:06 AM

I didn't have the best understanding of the zip format in the beginning but now I understand how "directories" inside a zip work.  For instance I was surprised to find that if you had an empty zip

and you added an empty folder called \\vehicles\\cars

and then a file \\vehicles\\cars\\viper.obj

you'd have 2 zip entries.

However again starting with an empty zip and this time only adding

\\vehicles\\cars\\viper.obj

would result in just one zip entry with no separate directory entry for  \\vehicles\\cars\\  in addition to the viper.obj  entry.

 

 

 

Coordinator
Oct 14, 2010 at 9:35 PM

Yes, that's correct: directory entries within a zip file are not container objects. And, there's no requirement for a directory entry to exist in the zip, if a file object exists that would occupy that directory if extracted.

So, give your new understanding, is there still a question, or a problem?