StartingGroovy
StartingGroovy

Reputation: 2860

Groovy - Zipping All Folders In A Directory

I have a folder located C:\Program Files\VideoEditing and inside there I currently have about 30 folders which I would like zip. While zipping it I would like to add an image to each newly zipped folder. (the image location is C:\Program Files\VideoEditing\art.png).

I was wondering if/how this might be possible in groovy?

My goal is to end up with 60 files/folders in my VideoEditing directory. (30 being the originals and 30 zipped versions with the image inside it)

I'm going to continue searching for more information on the topic, but figured I might as well post it in case someone already knows how to go about it.

.

EDIT

Based on andrei1089's suggestion of using AntBuilder, I assume the code would look something like:

File file = new File('C:\\Program Files\\VideoEditing')

fileDir = []
def ant = new AntBuilder()
int i = 0

file.eachDir {
    fileDir << it
}

fileDir.each { 
    ant.zip(//new file name = VidFolder_$i,
        //include folder,
        //include art.png,)    
}

What I don't know is how to include specifically each directory rather than certain file types.

Upvotes: 3

Views: 5377

Answers (2)

jpertino
jpertino

Reputation: 2219

a fileset will work just fine for simple cases

new AntBuilder().with {
  new File('src').eachDir {dir->
    zip destfile: "${dir.name}.zip", {
      fileset dir: dir
      fileset file: 'src/file.txt'
    }
  }
}

several examples that apply almost directly can be found in

Upvotes: 4

andrei1089
andrei1089

Reputation: 1108

You could try to use AntBuilder. Some useful examples can be found here

Upvotes: 1

Related Questions