Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print a fileset to a file, one file name per line?

Tags:

ant

fileset

I have a populated fileset and I need to print the matching filenames 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 the files on a single 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, should have been more specific - the list must not contain directories. I'm marking ChssPly76's as the accepted answer anyway, since the pathconvert command was exactly what I was missing. To strip the directories and list only the filenames, I used the "flatten" mapper.

Here is the script that 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> 
like image 313
Tomas Andrle Avatar asked Sep 21 '09 21:09

Tomas Andrle


People also ask

How do I print file names in files?

You can find this option under File / Print / Advanced / Mark and Bleeds / Page Information. This will take the file name and automatically place on the output. If you want more control then use the Document / Add Header / Footer command (or indeed any of the ones in the top category) ..

What is FileSet in build XML?

A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors.


1 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> 
like image 181
ChssPly76 Avatar answered Nov 11 '22 19:11

ChssPly76