How can I echo a filename twice using 'FileSet' and 'PathConvert'?
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>
<ech开发者_如何学Goo>${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?)
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>
精彩评论