在Groovy Zip文件/目录与AntBuilder [英] Zip files/Directories in Groovy with AntBuilder

查看:1465
本文介绍了在Groovy Zip文件/目录与AntBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用AntBuilder来压缩在Groovy文件和目录。我有以下的code:

I am trying to zip files and directories in Groovy using AntBuilder. I have the following code:

def ant = new AntBuilder()
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:file.name)

这呼啸而过的文件blah.txt,但没有文件新建文本文档。我认为这个问题是空间。我已经试过如下:

This zips the file "blah.txt", but not the file "New Text Document.txt". I think the issue is the spaces. I've tried the following:

ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"${file.name}")
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"\"${file.name}\"")

不属于上述两种解决了问题。我使用的是蚂蚁,因为它会压缩目录,我没有在工作中获得org.apache.commons.io.com pression。

Neither of the above resolved the issue. I'm using Ant because it will zip directories, and I don't have access to org.apache.commons.io.compression at work.

推荐答案

如果你看的对于蚂蚁拉链任务文档,参数描述为包括:

If you look at the docs for the ant zip task, the includes parameter is described as:

逗号或中必须包含的文件模式空格分隔

comma- or space-separated list of patterns of files that must be included

所以,你说得对,它是空间分隔的是打破它...

So you're right, that it is the space separator that's breaking it...

您需要使用较长的路线得到这个工作:

You need to use the longer route to get this to work:

new AntBuilder().zip( destFile: "${file}.zip" ) {
  fileset( dir: './Testing' ) {
    include( name:file.name )
  }
}

这篇关于在Groovy Zip文件/目录与AntBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆