LoginSignup
11
6

More than 5 years have passed since last update.

Groovyでzip処理(圧縮 and 解凍)

Last updated at Posted at 2012-12-26

圧縮

・フォルダ内のファイルを圧縮

def dir = $/C:\work\test/$
def zipfile = $/C:\work\a.zip/$
new AntBuilder().zip(destfile:zipfile,basedir:dir)

・特定のファイルをまとめて圧縮

def zipfile = $/C:\work\a.zip/$
def f1 = $/C:\work\20120613\a.txt/$
def f2 = $/C:\work\20120613\b.txt/$

new AntBuilder().zip(destfile:zipfile) {
  tarfileset(file : f1)
  tarfileset(file : f2)
}

解凍

new AntBuilder().unzip(src:"hoge.zip", dest:".") 

ちなみにgzipの場合

  • 圧縮 : 「zip」 → 「gzip」
  • 解凍 : 「unzip」 → 「gunzip」

まとめ

AntBuilderって便利!
ただ、あまりないとは思いますが、Groovyがインストールされていない環境で実行させる場合、「groovy-all-X.X.X.jar」以外にantのjarが必要になってくるので注意が必要。(grapを使用するなり、GROOVY_HOME内のlibにあるのを使用しましょう)
使用するタスクによって違うでしょうけど、今回の場合「ant-X.X.X.jar」、「ant-launcher-X.X.X.jar」が必要でした。

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6