Search code examples
javawindowslinuxpseudocode7zip

Zip - Add files and folders that are newer, remove old ones


I want to do the following on a Windows and Linux machine :

  • Zip several folders in an automated process

  • Add new files to archive, remove old ones.

I've experimented with .bat and .sh scripts using 7zip and have come across some limitations (not easy to update/remove from existing archive, Linux wants folders in .tar form first).

I have decided to write a Java application that will do the decision making (is archive out of date), and will call 7zip to compress the files.

I am thing of the following pseudo-code:

Get modified date of archive
Get latest modified date of files within folder
If latest modified date is later that archive date
    Delete archive
    Create new archive

There will several archives within a folder hierarchy, so if a folder is needed to be updated this will cut the processing down.

Sound good? Or is there another, simpler method around?


Solution

  • I would suggest you use java.util.zip instead of 7zip if you really want to do this in Java.

    A better solution might be to do 7z -u and then play around with the options.

    http://sevenzip.sourceforge.jp/chm/cmdline/switches/update.htm