views:

404

answers:

1

Hey,

So i have this simple ant task that lists all png files in a folder.

<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>

This prints

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

But what i want is for each filename to appear twice on the same line.

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

Is this possible with the default pathconvert?

This question is a follow on from this http://stackoverflow.com/questions/1456852/ant-commands-to-print-fileset-into-a-file-one-match-per-line

+1  A: 

You could use a regexp mapper (instead of the flatten) that implements the flattening and duplication. This is pretty simplistic, but might do:

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

Would need adjusting for your local path separator.

Better though, use a chainedmapper in place of the flatten:

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