【问题标题】:How can I echo a filename twice using 'FileSet' and 'PathConvert'?如何使用“FileSet”和“PathConvert”两次回显文件名?
【发布时间】:2010-06-02 11:43:42
【问题描述】:

我有一个简单的 Ant 任务,它列出了一个文件夹中的所有“.png”文件:

<target name="listimages">
    <!-- Assume files a A and B -->
    <fileset id="dist.contents" dir="${basedir}">
        <include name="**/*.png"/>
    </fileset>

    <pathconvert pathsep="${line.separator}"
                 property="prop.dist.contents" 
                 refid="dist.contents">
        <mapper type="flatten" />
        <map from="${basedir}" to=""/>
    </pathconvert>
    <echo>${prop.dist.contents}</echo>
</target>

打印出来

[echo] A.png
[echo] B.png

但是,我想要的是文件名在每一行出现两次。

[echo] A.png,A.png
[echo] B.png,B.png

我该怎么做?

(这个问题是How can I print a fileset to a file, one file name per line?的后续问题)

【问题讨论】:

    标签: ant fileset


    【解决方案1】:

    您可以使用实现展平和复制的regexp mapper(而不是展平)。这很简单,但可能会:

    <mapper type="regexp" from=".*/(.*)" to="\1,\1" />
    

    需要针对您的本地路径分隔符进行调整。

    不过,最好使用chainedmapper 代替flatten:

    <chainedmapper>
        <mapper type="flatten" />
        <mapper type="regexp" from="(.*)" to="\1,\1" />
    </chainedmapper>
    

    【讨论】:

      猜你喜欢
      • 2011-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2019-08-27
      相关资源
      最近更新 更多