How to print a set of files to a file, one file name per line?

I have a completed set of files, and I need to print the corresponding file names into a text file.

I tried this:

<fileset id="myfileset" dir="../sounds"> <include name="*.wav" /> <include name="*.ogg" /> </fileset> <property name="sounds" refid="myfileset" /> <echo file="sounds.txt">${sounds}</echo> 

which prints all files on one line, separated by semicolons. I need to have one file per line. How can I do this without resorting to calling OS commands or writing Java code?

UPDATE

Ah, it should have been more specific - the list should not contain directories. I still mark ChssPly76 as an accepted answer, since the pathconvert command was exactly what I was missing. To split directories and list only file names, I used the "flatten" mapper .

Here is the script I ended up with:

 <fileset id="sounds_fileset" dir="../sound"> <include name="*.wav" /> <include name="*.ogg" /> </fileset> <pathconvert pathsep="&#xA;" property="sounds" refid="sounds_fileset"> <mapper type="flatten" /> </pathconvert> <echo file="sounds.txt">${sounds}</echo> 
+41
ant fileset
Sep 21 '09 at 21:05
source share
2 answers

Use the PathConvert task:

 <fileset id="myfileset" dir="../sounds"> <include name="*.wav" /> <include name="*.ogg" /> </fileset> <pathconvert pathsep="${line.separator}" property="sounds" refid="myfileset"> <!-- Add this if you want the path stripped --> <mapper> <flattenmapper /> </mapper> </pathconvert> <echo file="sounds.txt">${sounds}</echo> 
+64
Sep 21 '09 at 21:11
source share

Since Ant 1.6 you can use toString :

 <echo file="sounds.txt">${toString:myfileset}</echo> 
0
Feb 02 '17 at 8:44
source share



All Articles