3

I need to create a service that finds specific folders and archives them into on zip file.

I saw all kind of examples, but it seems that have to read all the files in every folder. Am I right?

Is there another way to do that (maybe using truezip for that matter)?

I want to use truezip since I understood you could easily add files/folders to a zip file.

I've searched for a simple example of archiving a folder using truezip - but I couldn't find anything useful - I need a simple example of how to archive a given folder.

I'm using Java 6. How to archive a folder in Java using truezip?

EDIT: Also found this example.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Noam
  • 3,049
  • 10
  • 34
  • 52
  • The 1st linked example uses a hard-coded list of files. Use the methods of the [`File`](http://docs.oracle.com/javase/7/docs/api/java/io/File.html) API to list the files and directories, call that recursively for each directory - for a list of all files in all sub-directories. – Andrew Thompson Dec 09 '12 at 11:30
  • [DirectoryWalker](http://commons.apache.org/io/api-release/org/apache/commons/io/DirectoryWalker.html) from Commons IO can help you to simplify the task of interating over files and recursing into subdirectories. – fvu Dec 09 '12 at 11:52

1 Answers1

1

Using TrueZIP, all you need to call is

new TFile("folder").cp_rp(new TFile("archive.zip"));

I suggest to read it's tutorial in order to get a better understanding of what it all means: TrueZIP Tutorial

Christian Schlichtherle
  • 3,125
  • 1
  • 23
  • 47
  • Thanks, It seems right - but I didn't try it. I used ZipOutputStream instead. If I change my mind I will post here. – Noam Dec 12 '12 at 11:38