You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Emmanouil Batsis (Manos)" <ma...@abiss.gr> on 2011/08/12 20:10:21 UTC

zipFile.getEntries() not containing archive root folder?

Consider a zip archive containing the following folder and files:

rootfolder
+ file1.doc
+ file2.pdf

Shouldnt the "entries" enum bellow contain an entry for the root folder?


ZipFile zipFile = new ZipFile(tmpZipFile);
Enumeration entries = zipFile.getEntries();
while (entries.hasMoreElements()){
    if (entry.isDirectory()){
       // this should be executed once right?
       LOG.info("found folder!")
    }
    else{
       LOG.info("found file!")
    }
}

Manos

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: zipFile.getEntries() not containing archive root folder?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-08-13, Emmanouil Batsis (Manos) wrote:

> On 08/13/2011 07:19 AM, Stefan Bodewig wrote:
>> If you use some ZIP tool with a UI like "Windows Compressed Folders",
>> WinZip, 7ZIP or PKZIP they will show you the folders even if those are
>> not part of the archive - they simply don't have any other way to
>> visualize the entries.

> That was it.

Good.

> The zip came from a rather non-techie client as a testcase, will need
> to check out how it was created. This may not be a bug but it could be
> a valid a feature request, e.g. a flag to control whether entries
> should be constructed for such folders.

On the reading or the writing side?

In either case the corresponding Ant tasks would hold code that you
could leverage (although the extract logic really isn't difficult - does
File.getParentFile() exist?  No => call getParentFile().mkdirs()).

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: zipFile.getEntries() not containing archive root folder?

Posted by "Emmanouil Batsis (Manos)" <ma...@abiss.gr>.
On 08/13/2011 07:19 AM, Stefan Bodewig wrote:
> If you use some ZIP tool with a UI like "Windows Compressed Folders",
> WinZip, 7ZIP or PKZIP they will show you the folders even if those are
> not part of the archive - they simply don't have any other way to
> visualize the entries.

That was it. Trying unzip -l ARCHIVE on my linuxbox showed no explicit 
entry for the directory, although that is created by GUI tools when 
extracting the archive. The "Archive Managher" GUI tool however shows a 
dir inferred by the entry names, e.g.:

rootfolder/filename.pdf

The zip came from a rather non-techie client as a testcase, will need to 
check out how it was created. This may not be a bug but it could be a 
valid a feature request, e.g. a flag to control whether entries should 
be constructed for such folders.

In my case I need to iterate for folders first and make appropriate 
business/DB calls before actually extracting each file so this is a 
liability I accidentally stumbled upon before going live ;-)

Many thanks for your patience and help.

Manos

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: zipFile.getEntries() not containing archive root folder?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-08-12, Emmanouil Batsis (Manos) wrote:

> On 08/12/2011 10:09 PM, Stefan Bodewig wrote:
>> On 2011-08-12, Emmanouil Batsis (Manos) wrote:

>>> Consider a zip archive containing the following folder and files:

>>> rootfolder
>>>> file1.doc
>>>> file2.pdf

>>> Shouldnt the "entries" enum bellow contain an entry for the root folder?

>>> ZipFile zipFile = new ZipFile(tmpZipFile);
>>> Enumeration entries = zipFile.getEntries();

>> If "rootfolder" is part of the archive, yes.  And I'm pretty sure it
>> does (it will hav the name "rootfolder/").

> Its something about the specific zip archive, must be. If I extract
> its contents and make a new zip on my machine it works just
> fine. Should i open a bug or something?

Maybe we can try a few other things first.

ZipFile will only return entries that are really inside the archive.  If
the archive contains files with names that indicate they were part of a
deeper directory tree, this is fine and the directories themselves need
not be part of the archive themselves.

If you use some ZIP tool with a UI like "Windows Compressed Folders",
WinZip, 7ZIP or PKZIP they will show you the folders even if those are
not part of the archive - they simply don't have any other way to
visualize the entries.

I suspect your archive in question simply only contains the file
entries.  Ant's <zip> task with filesonly="true" would create such an
archive, for example.  Are you sure your archive contains "rootfolder"
at all?

The only tool I'd know off-hand you could use to test this would be
InfoZIP's command line tools.  "unzip -l ARCHIVE" should show you the
contents.  Your JDK's jar might work as well (jar -tf ARCHIVE).

When in doubt, open a JIRA ticket and we can go from there.  If you
can't share the archive in public but could do so privately to one of us
Commons committers then we surely can arrange something as well.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: zipFile.getEntries() not containing archive root folder?

Posted by "Emmanouil Batsis (Manos)" <ma...@abiss.gr>.
On 08/12/2011 10:09 PM, Stefan Bodewig wrote:
> On 2011-08-12, Emmanouil Batsis (Manos) wrote:
>
>> Consider a zip archive containing the following folder and files:
>
>> rootfolder
>> + file1.doc
>> + file2.pdf
>
>> Shouldnt the "entries" enum bellow contain an entry for the root folder?
>
>> ZipFile zipFile = new ZipFile(tmpZipFile);
>> Enumeration entries = zipFile.getEntries();
>
> If "rootfolder" is part of the archive, yes.  And I'm pretty sure it
> does (it will hav the name "rootfolder/").

Its something about the specific zip archive, must be. If I extract its 
contents and make a new zip on my machine it works just fine. Should i 
open a bug or something?

Manos

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: zipFile.getEntries() not containing archive root folder?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-08-12, Emmanouil Batsis (Manos) wrote:

> Consider a zip archive containing the following folder and files:

> rootfolder
>+ file1.doc
>+ file2.pdf

> Shouldnt the "entries" enum bellow contain an entry for the root folder?

> ZipFile zipFile = new ZipFile(tmpZipFile);
> Enumeration entries = zipFile.getEntries();

If "rootfolder" is part of the archive, yes.  And I'm pretty sure it
does (it will hav the name "rootfolder/").

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org