【问题标题】:Zip files/Directories in Groovy with AntBuilder使用 AntBuilder 在 Groovy 中压缩文件/目录
【发布时间】:2012-12-22 21:54:14
【问题描述】:

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

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

这会压缩文件“blah.txt”,但不会压缩文件“New Text Document.txt”。我认为问题是空间。我尝试了以下方法:

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。

【问题讨论】:

  • 向我们介绍您的环境(操作系统、Groovy 版本等)

标签: ant groovy antbuilder


【解决方案1】:

如果你看docs for the ant zip task,includes参数描述为:

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

所以你是对的,它是打破它的空格分隔符......

您需要使用更长的路线才能使其工作:

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

【讨论】:

    猜你喜欢
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多