Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Zip file creation with directory suppression through an API

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So here's the deal. I can easily create a zip file using Apache's compression API. That's all good. The problem I'm having is suppressing the directory structure when its zipped. How make a zip file w/the following requirements? Inside the zip I need the file to have no directory structure and only be in a list. The files however need to be zipped from a directory.

Here's a more complete picture of what I'm trying to do. I have the following directory structure and list of files...



after I zip up the files and everything, I get a zip file called



Now when I open the zip I want to only find the files at the root level.



Note that the files are in the base directory. There are lots of examples out there of how to zip up a bunch of files however none of them show me how to suppress the directory structure. Also I don't have the rights to the root directory so I can't simply move the files to the root and re-zip from there. I have to zip them from the directory structure I'm in. One other thing, I've noticed that pkzip has the features to do something like this, unfortunately I can't copy pkzip onto this server. I can only use the standard unix files and public APIs.

Thanks,

Dale

 
Marshal
Posts: 27900
94
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a ZipOutputStream (see the java.util.zip package). You control the names of the files via ZipEntry objects and it's entirely up to you what names you use.
 
Marshal
Posts: 78428
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this question is too difficult for "beginning", so I shall move it.
 
Nothing? Or something? Like this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic