在 Groovy Ant 任务中保留原始文件名

编程入门 行业动态 更新时间:2024-10-13 10:30:00
本文介绍了在 Groovy Ant 任务中保留原始文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有以下代码:

new AntBuilder().zip( destFile: "${file}.zip" ) {
        fileset( dir: srcDir ) {
            include( name:pattern )
        }
    }

在这个例子中,我希望 ant 创建一个与原始文件同名的 zip,但在末尾添加了 .zip. 有没有办法在不知道的情况下做到这一点在ant中提前原始文件的名称?我也希望能够对其他蚂蚁任务做同样的事情.

In this example I'd like ant to create a zip with the same name as the original file, but with a .zip added to the end. Is there a way to do this without knowing the original file's name ahead of time in ant? I'd like to be able to do the same thing with other ant tasks as well.

换句话说,我希望文件名成为每个文件解析为的任何模式".

To put it another way, I'd like the filename to become whatever "pattern" resolves to for each file.

推荐答案

类似的事情?

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

    <dirset id="dirsToZip" dir="src">
        <include name="dir*"/>
    </dirset>

    <groovy>
        project.references.dirsToZip.each { 
            ant.zip(destfile: "${it}.zip", basedir: it)
        }
    </groovy>
</target>

如果发现 groovy 任务能够遍历文件集或目录集,这是一个非常有用的功能.

If find the groovy task's ability to iterate thru a fileset or dirset a very useful feature.

这篇关于在 Groovy Ant 任务中保留原始文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-20 09:12:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/980027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   原始   Groovy   Ant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!