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 / October 2006

Tip: Looking for answers? Try searching our database.

space in file name

Thread view: 
unwantedspam - 12 Oct 2006 15:41 GMT
Hello All,
Thank you in advance. I am using java.util.zip to zip several folders
and subfolders. When I try and zip a folder
(c:\inetpub\wwwroot\test\this is a test) it works fine. But when I
unzip it, I get the directory structure (inetpub\wwwroot\test\this is a
test) along with the files. If I remove the spaces
(c:\inetpub\wwwroot\test\this_is_a_test) I get this_is_a_test and the
files I need. Is there a work around for this. What I am hoping to get
is (this is a test) and all of the files.

Thanks again
Chris Uppal - 13 Oct 2006 11:35 GMT
> Thank you in advance. I am using java.util.zip to zip several folders
> and subfolders. When I try and zip a folder
[quoted text clipped - 4 lines]
> files I need. Is there a work around for this. What I am hoping to get
> is (this is a test) and all of the files.

I'm not sure what your problem is (I can't understand your explanation).  But
it sounds as if you /might/ be making one of three common mistakes when you are
building your ZIP file.  If so then it would be worthwhile fixing it or them
and see if the problem goes away.

The first is that it is easy to forget that '\' is not a path separator in ZIP
files.  You must /always/ use a forward slash '/', even on Windows.

The second is that you don't normally want to add entries corresponding to the
directories themselves (it's not illegal, but it can confuse some ZIP file
readers).  So you just have entries for the actual files and leave the reader
to deduce the directories.

The third is that if you /do/ add entries for directories, then the last
character in the name of each /must/ be '/' (and never '\').

If none of that helps, then it would be worthwhile clarifying exactly what you
are using to read the ZIP file -- it might be a bug in the reader rather than
any problem with the ZIP file itself.

   -- chris
unwantedspam - 13 Oct 2006 15:34 GMT
> > Thank you in advance. I am using java.util.zip to zip several folders
> > and subfolders. When I try and zip a folder
[quoted text clipped - 26 lines]
>
>     -- chris

Chris,
Thank you for your response. I have replaced the "\" with "/" and the
same thing is happening.

I will try to explain this a little better. : )

Basically, say I zip the folder: "c:\inetpub\wwwroot\test\this is a
test\". When I open the zip file it has the exact same folder
structure: "inetpub\wwwroot\test\this is a test" with all of the files
that are "under" the folder "this is a test".

Now, if I zip the folder: "c:\inetpub\wwwroot\test\this_is_a_test\" and
open the zip file it only has "this_is_a_test" with all of the files
that are "under" the folder "this_is_a_test". This is what I want to
happen but with folders with spaces in the name like "This is a test".

I am not adding entries for the directories. I am using
file.getAbsolutePath.

Hopefully a explained this a little better. Is there an escape
character I need to use in "front" of the space?

Thanks again for your help.
Chris Uppal - 16 Oct 2006 10:55 GMT
> Basically, say I zip the folder: "c:\inetpub\wwwroot\test\this is a
> test\". When I open the zip file it has the exact same folder
[quoted text clipped - 8 lines]
> I am not adding entries for the directories. I am using
> file.getAbsolutePath.

So you are getting the absolute pathname of the file, and using that, unchanged
except for replacing '\' with '/' as the name to use for the ZipEntry; am I
understanding you correctly ?

Also, if I read you right, in both cases the directory and its contents are
written to the zipfile, but the differences is that in the case where there are
spaces in the directory name, the name that appears in the zipfile has several
components (inetpub/wwwroot/test/this_is_a_test), but if the folder's name has
no spaces, then all the ZipEntries are given shorter names without the
"inetpub/wwwroot/test/" prefix ?

> Is there an escape
> character I need to use in "front" of the space?

No.  There is no need (and in fact no way) to escape the space.

I think this must be a problem somewhere in the code you use to create the
zipfile.  I would add some tracing (or use a debugger) to find exactly what
names your code is giving the ZipEntries.  I'm pretty sure you'll find the
problem there, i.e. that this is nothing to do with zip files themselves (or
their Java implementation).

   -- chirs
unwantedspam - 17 Oct 2006 00:08 GMT
> > Basically, say I zip the folder: "c:\inetpub\wwwroot\test\this is a
> > test\". When I open the zip file it has the exact same folder
[quoted text clipped - 32 lines]
>
>     -- chirs

Chris,
Thanks again very much for your response. I greatly appreciate your
help.

> So you are getting the absolute pathname of the file, and using that, unchanged
> except for replacing '\' with '/' as the name to use for the ZipEntry; am I
> understanding you correctly ?
Yes, you are correct

> Also, if I read you right, in both cases the directory and its contents are
> written to the zipfile, but the differences is that in the case where there are
> spaces in the directory name, the name that appears in the zipfile has several
> components (inetpub/wwwroot/test/this_is_a_test), but if the folder's name has
> no spaces, then all the ZipEntries are given shorter names without the
> "inetpub/wwwroot/test/" prefix ?
Yes and no. Yes, the directories and all of the contents are being
written to the zip file. No, the name is correct. I am creating a zip
file called test.zip from the directory c:\inetpub\wwwroot\test\this is
a test. When I extract this file to my desktop, I get the directory
structure desktop\inetpub\wwwroot\test\this is a test. This is
incorrect. It should be desktop\this is a test. If I use the directory
structure c:\inetpub\wwwroot\test\this_is_a_test. Everything works
fine. When I extract this file to the desktop, I get the directory
structue desktop\this_is_a_test.

> I think this must be a problem somewhere in the code you use to create the
> zipfile.  I would add some tracing (or use a debugger) to find exactly what
> names your code is giving the ZipEntries.  I'm pretty sure you'll find the
> problem there, i.e. that this is nothing to do with zip files themselves (or
> their Java implementation).
I will try this. Thanks for the suggestion.

>     -- chirs
Again, thank you very much.

If you have any other suggestions I would greatly appreciate it.
Chris Uppal - 18 Oct 2006 12:27 GMT
[me:]

> > So you are getting the absolute pathname of the file, and using that,
> > unchanged except for replacing '\' with '/' as the name to use for the
> > ZipEntry; am I understanding you correctly ?
> Yes, you are correct

Then I think that's probably half your problem there.  ZIP files are not meant
to contain "absolute" paths (think what would happen if a naive client
extracted 'C:\Windows\system32\somethingVital.dll' without checking, for
instance).  Unless you are creating the ZIP file for very special purposes
(i.e. not the be read by a general reader) then each filename should be of the
form:
   dir1/dir2/filename
where "dir1" does NOT start with '/'.

> When I extract this file to my desktop, I get the directory
> structure desktop\inetpub\wwwroot\test\this is a test. This is
> incorrect.

And I think that's the other half of your problem.  The ZIP file reader which
is built into Windows XP (and later) is fairly deeply broken.  For one thing it
(stupidly) attempts to interpret filenames with '\' in them (which probably
mislead you from the start), for another thing, it simply doesn't work with
entries including the ':' or ';' character in the filename.  I'm sure it has
other problems too.  This is why I kept asking what reader you were using.  If
you use the unzip utility I mentioned, then you'll find out what is /actually/
in the ZIP file, not what MS's broken reader /thinks/ is in there.

I can't, by the way, reproduce exactly the symptoms you are seeing, so there
may be other problems still to be resolved, but I'd bet that the combo of
Windows and the ':' character is causing at least some of the problems.

   -- chris


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



©2009 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.