【问题标题】:How to get all the filenames from a directory using ant如何使用ant从目录中获取所有文件名
【发布时间】:2013-07-24 05:53:47
【问题描述】:

使用 ant 我想从目录中获取所有文件名并创建一个属性,其值为逗号分隔的文件名。

示例:如果我们在一个目录中有 3 个文件(即 1.txt、2.txt、3.txt),那么我们必须创建一个属性,其值应为 1.txt、2.txt、3.txt .

谢谢, 曼苏尔医学博士。

【问题讨论】:

  • 你的最终目标是什么?你想用这个属性做什么?

标签: ant


【解决方案1】:

首先,您需要创建一个包含文件的路径:

<path>
    <fileset dir="${dir.name}">
          <include name="*"/>
    </fileset>
</path>

这可以与&lt;pathconvert&gt; 任务结合使用:

<pathconvert pathsep=","
    property="my.files">
    <path>
        <fileset dir="${dir.name}">
            <include name="*"/>
        </fileset>
    </path>
</pathconvert>

属性${my.files} 将包含一个逗号分隔的文件列表。

如果您愿意,可以分两步完成:

<path id="mypath">
    <fileset dir="${dir.name}">
          <include name="*"/>
    </fileset>
</path>

<pathconvert pathsep=","
    property="my.files"
    refid="mypath"/>

Word 'o Warning:它还将包含这些文件的完整路径

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    相关资源
    最近更新 更多