This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Zipping Directory Structure - Need to Chop Off First Few Directories

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A web application I am working on stores files on AmazonS3 and I give the user the option of downloading a handful of files at once. These files are pulled down from AS3 then I zip them up before shipping them off to the user. This is a grails app so m code is in Groovy but it's just the Zip API so should be close enough for help here.

I download the files (which include directories of their own) into an initial drop spot. Something like:

/applications/thehighbar/attachments/board/

And then the system creates a user directory and a timestamp directory so I end up with this..

/applications/thehighbar/attachments/board/1234/102343254354/

Then my files are downloaded into that directory and I end up with...

/applications/thehighbar/attachments/board/1234/102343254354/2010/something/foo/file001.txt
/applications/thehighbar/attachments/board/1234/102343254354/2010/something/foo/file002.txt
/applications/thehighbar/attachments/board/1234/102343254354/2010/something/boo/boo001.png

You get the idea. The problem is that when I zip this up, the zip file contains /applications/... all the way to the actual files. I really need to start at 2010, although it won't always say 2010. So basically, I need to chop off /applications/thehighbar/attachments/board/1234/102343254354/ so they don't get zipped into the zip file. Here's my code..



loopFile is a File object that represents everything from /applications/ up to where 2010 starts. I then loop over all the directories and files within that structure. But since the File has an absolute path starting with /applications/ those still get zipped up as part of the structure. I realize this is kind of confusing. I hope it makes enough sense.

 
Sheriff
Posts: 24658
58
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't you just replace

by

where the shortVersion method returns the jar path you want to see?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. Let me give that a shot.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect Paul! Worked great. Thank you.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!