2011-08-04 4 views
1

다음과 같은 문제가 있습니다 : 1. 12345678.xml-out과 12345678.xml을 파일로 만들어야하고 12345로 압축해야합니다. .지퍼.Groovy/Ant : Ant에서 Groovy 루프로 두 파일 압축하기

<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