使用 AntBuilder 在 Groovy 中压缩文件/目录 [英] Zip files/Directories in Groovy with AntBuilder

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

问题描述

我正在尝试使用 AntBuilder 在 Groovy 中压缩文件和目录.我有以下代码:

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",但不会压缩文件New Text Document.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}\"")

以上都没有解决问题.我使用 Ant 是因为它会压缩目录,而我在工作时无法访问 org.apache.commons.io.compression.

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.

推荐答案

如果你看一下 ant zip 任务的文档,includes 参数描述为:

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 )
  }
}

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

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