This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Zipping files

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First let me explain what I need to achieve using my Java application. There is directory : XXX, inside this dir. there are some more dir. like A,B,C. There can be an image file 123.jpg which can be present in each of these dir. and that too with the same name. Basically, XXX\123.jpg, XXX\A\123.jpg and so on.
Now the problem I face when i try to zip all files in the folder XXX recursively is, that only one entry for the file 123.jpg is present in the resultant ZIP file.
The code I'm using to zip is as follows:


Any help would be really appreciated~
[ January 18, 2006: Message edited by: Anirvan Majumdar ]
 
Sheriff
Posts: 26798
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This causes the name in the zip file to be only "123.jpg", whereas you want that to be prefixed by the file path, or perhaps the part of the file path that comes after "XXX".
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing that out Paul, but if i don't use


What other alternative could I use??
 
Paul Clapham
Sheriff
Posts: 26798
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would use some other alternative that builds up the file name you want to use in the zip file. Extracting something from the end of the full path would do what you want. I think it would, because you haven't said what you want. That should be your first step.

Usually when I see zip files containing directories, the path names are relative path names. So I think you would want 123.jpg, A\123.jpg, and so on.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that the fileNames array is redundant here since the fileList array already contains this information via appropriate method calls. In fact, it will contain the complete path name that differentiates XXX/123.jpg from YYY/123.jpg. Typically the same directory structure is used inside a zip file in situations like this. I think a File object can also give you a relative path from some chosen location. I don't know the exact details, but that's what the API docs are for.

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic