Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Unzip a file into proper directory structure

Thread view: 
Java and Swing - 17 May 2006 12:17 GMT
I have a directory structure that I am going to zip up, such as...

c:\
   foo\
       abc.txt
   bar\
       myinfo.doc
       mynotes.xls
   zoo\
       animals\
           elephant.jpg

so I zip up the entire C: directory (in this case it only has three
directories and four files).  So when I attempt to unzip this file on
some other hard drive, I want it to extract the files and put them into
their correct directories, i.e. foo\, bar\, zoo\animals.  How do i do
this?  I know I can extract a file from the zip, but don't I have to
first make sure the path exists before I can extract it properly?

thanks
Java and Swing - 17 May 2006 12:41 GMT
I got it.  Basically you get the zip entries and has you loop through
them you can call, ZipEntry.isDirectory() ....if it is, then create a
new File object, and then File.mkdirs().
Daniel - 18 May 2006 02:49 GMT
From my experience it is not exactly that easy. You will get away with
that most of the time.
From what I understand is that the path can be stored differently in
the zipfile depending on who creates the zip.
First there is the one version you vae encountered, where you have
directory nodes. This is easy to handle, as you discovered.
second there is the case where the name of the file include the full
path, but no directory nodes are written, so you have to use the name
of the file to know where it goes.

last is a little gotcha for the solution you have.. you do not always
know if the directory nodes will appear before the files in the file.
so that means that you may have to go through the zip twice, once for
finding all directories, and one for extracting files..

much more of this is available online, basicaly use google to find
mroe posts regarding this.

regards
Daniel

>I got it.  Basically you get the zip entries and has you loop through
>them you can call, ZipEntry.isDirectory() ....if it is, then create a
>new File object, and then File.mkdirs().


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.