Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a comma-delimited file list with Ant

Tags:

java

ant

I'm trying to create a comma-delimited list of files or directories under the current directory. For instance, suppose I have the following folder structure:

Root
-- Directory1
-- Directory2
...

I want to generate a variable or property that contain "Directory1,Directory2." I've tried iterating (using ant-contrib "for" task) over a <dirset dir="." includes="*">, but this generates absolute paths; I've then extracted the file names using the "basename" task, however that in turn generates an output property. Since properties are immutable, what I get in practice is "Directory1,Directory1,..."

Is there a saner way of doing this, or will I have to write a Java extension to do this for me?

like image 409
Tomer Gabel Avatar asked Jul 19 '09 10:07

Tomer Gabel


1 Answers

The pathconvert task can be used to format a dirset with arbitrary separators:

<dirset id="dirs" dir="." includes="*"/>
<pathconvert dirsep="/" pathsep="," property="dirs" refid="dirs"/>
<echo message="${dirs}"/>
like image 120
Jörn Horstmann Avatar answered Oct 11 '22 11:10

Jörn Horstmann