如何构建文件名列表? [英] How do I build a list of file names?

查看:43
本文介绍了如何构建文件名列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个 Ant 目标,将文件夹中的.jar"文件名列表附加在一起(以逗号分隔)到一个变量中,该变量稍后用作外部实用程序的输入.我遇到了范围和不变性的障碍.我可以访问 ant-contrib,但不幸的是,我坚持使用的版本无法访问for"任务.这是我到目前为止所拥有的:

I need to write an Ant target that appends together (comma-delimited) a list of '.jar' file names from a folder into a variable, which is later used as input to an outside utility. I am running into barriers of scope and immutability. I have access to ant-contrib, but unfortunately the version I am stuck with does not have access to the 'for' task. Here's what I have so far:

<target name="getPrependJars">
    <var name="prependJars" value="" />
    <foreach param="file" target="appendJarPath">
        <path>
            <fileset dir="${project.name}/hotfixes">
                <include name="*.jar"/>
            </fileset>
        </path>         
    </foreach>

    <echo message="result ${prependJars}" />
</target>


<target name="appendJarPath">
    <if>
        <equals arg1="${prependJars}" arg2="" />
        <then>
            <var name="prependJars" value="-prependJars ${file}" />
        </then>
        <else>
            <var name="prependJars" value="${prependJars},${file}" />
        </else>
    </if>       
</target>

'appendJarPath' 似乎只在它自己的范围内修改了 'prependJars'.作为测试,我尝试使用antcallback",它适用于单个目标调用,但对我的文件列表帮助不大.

It seems that 'appendJarPath' only modifies 'prependJars' within its own scope. As a test, I tried using 'antcallback' which works for a single target call, but does not help me very much with my list of files.

我意识到我的工作有点违背常规,并且在绝大多数情况下词法范围是可取的,但我真的想让它以一种或另一种方式工作.有没有人有解决这个问题的创意?

I realize that I am working somewhat against the grain, and lexical scope is desirable in the vast majority of instances, but i really would like to get this working one way or another. Does anybody have any creative ideas to solve this problem?

推荐答案

您或许可以使用 pathconvert 任务,它允许您将分隔符指定为逗号.

You might be able to use the pathconvert task, which allows you to specify the separator character as comma.

<target name="getPrependJars">
    <fileset id="appendJars" dir="${project.name}/hotfixes">
        <include name="*.jar" />
    </fileset>
    <pathconvert property="prependJars" refid="appendJars" pathsep="," />

    <echo message="prependJars: ${prependJars}" />
</target>

这篇关于如何构建文件名列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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