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

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

问题描述

我需要编写附加在一起(以逗号分隔)的'的.jar文件名的列表,从文件夹到一个变量,它后来被用作输入到外部工具Ant目标。
我遇到的范围和永恒性的障碍。我有机会获得蚂蚁的contrib,但不幸的是我坚持的版本没有进入'的'任务。这是我到目前为止有:

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天全站免登陆