Question

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 the filenames to appear twice on each line.

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

How can I do that?

(This question is a follow up to How can I print a fileset to a file, one file name per line?)

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top