views:

607

answers:

3

I am trying to zip an entire directory in a groovy program. I have used the built in ant target to zip the directory and normally this works, except that sometimes 2-3 files are in use which I don't care about but the zip code actually aborts because of that - any ideas on how to fix this?

Thanks!

Code:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/temp.zip", 
    basedir: "c:/Temp/"
)
A: 

So the solution that I am currently using is the ignore the files that are in use since they are always the same... I put them in an exclude clause, see below:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/Temp.zip", 
    basedir: "c:/Temp",
    level: 9,
    excludes: "**/file1.dat, **/file2.dat, **/file3.dat"
)

I am still open to a better solution!

Autobyte
A: 

There is no "better" solution, as the main issue seems to be that you're using your Application (Firefox) while zipping its working files.

You could implement your own zip mechanism, using ZipOutputStream and so on, but you'll have the same issue as long as you don't either close Firefox or check periodically that all the files are lock free before zipping them.

gizmo
That's what I was thinking and the files that are locked are not essential to the backup of the firefox environment anyways - thanks!
Autobyte
+1  A: 

I'm not familiar with Groovy or AntBuilder, but I believe you can use the VShadow program to create a volume shadow copy of the directory, and do the backup from there.

Create a volume shadow copy of drive C:

vshadow -p C:

Mount the shadow copy as a new drive letter:

vshadow -el=ShadowCopyId,Z:

The drive Z: will then be a copy of C: which should allow you to open the files.

And when you're done, delete the shadow copy:

vshadow -ds=ShadowCopyId

Kris Peters