开发者

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 o开发者_如何学Criginals 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.


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

  • http://ant.apache.org/manual/Tasks/zip.html
  • http://ant.apache.org/manual/Types/fileset.html
  • http://ant.apache.org/manual/Types/zipfileset.html


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜