【问题标题】:How to get archive name while unzipping如何在解压缩时获取存档名称
【发布时间】:2011-01-14 04:13:48
【问题描述】:

我正在使用 ant 解压缩任务来获取存档文件的内容。

是否有可能以某种方式保存该存档的名称。

以下是我用来解压缩档案的代码。

    <unzip dest="${import.dir}">
        <fileset dir="${tmp.dir}">
            <include name="**/*.zip"/>
        </fileset>   
    </unzip>

问候, 萨提亚

【问题讨论】:

  • 你总是只匹配一个存档吗?或者,如果匹配多个会发生什么?你需要这个名字来做什么 - 只是为了记录或显示 - 或者更多?
  • 是的,tmp.dir 总是只有一个 zip。我需要该存档 nae 才能登录数据库。

标签: ant


【解决方案1】:

您可以使用嵌入式 groovy 脚本

<target name="unzip">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <fileset id="zips" dir="${tmp.dir}" includes="**/*.zip"/>

    <groovy>
        project.references.zips.each { file ->
            ant.echo(message:"message goes here", file:"build.log", append:true)
            ant.unzip(src:file, dest:properties["import.dir"])
        }
    </groovy>
</target>

Groovy 任务记录在案here

【讨论】:

    猜你喜欢
    • 2022-12-21
    • 2021-11-01
    • 2019-07-29
    • 2014-10-08
    • 1970-01-01
    • 2011-01-20
    • 2011-03-27
    • 2021-01-01
    相关资源
    最近更新 更多