2011-08-04 7 views
1

私は以下の問題があります。 1.)私は12345678.xml-outと12345678.xmlをファイルしなければならず、12345 .zip。Groovy/Ant:Groovyのループ内の2つのファイルをZIPで処理します。

<target> 
    <groovy> 

    import java.util.regex.Pattern 
    import java.util.regex.Matcher 

    (...) 
     f.eachFileMatch { it.split("\\.")[1].length()==7 } { 
      (.. do something and then zip) 

       def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/temp.zip", 
    fileset: HERE I NEED A PATTERN MATCH with the GROOVY it variable... 
) 
     } 

    </groovy> 

</target> 

2)一般的な質問: 問題は、私はそのディレクトリに、このようなペアを複数が存在する可能性があるためループを持っているantBuilderオブジェクトでグルーヴィーな変数を使用する可能性はあるの?

+0

代わりにジップを行うには、このようなものを使用できますか? http://commons.apache.org/compress/examples.html –

答えて

0

このようなことはありますか?

<target> 
    <groovy> 
    def ant = new AntBuilder() 
    def pattern = ~/([0-9]{7}).xml/ 
    def base = new File('.') 
    base.eachFileMatch(pattern) { f -> 
     def prefix = (f.name =~ pattern)[0][1] 
     ant.zip(
     basedir: base, 
     destfile: "${prefix}.zip", 
     includes: "${prefix}.xml,${prefix}.xml-out" 
    ) 
    } 
    </groovy> 
</target> 
+0

はい、完璧に動作します! – Booyeoo

関連する問題