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

寵の児 提交于 2019-11-28 17:01:07

问题


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>

回答1:


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>



回答2:


Since Ant 1.6 you can use toString:

<echo file="sounds.txt">${toString:myfileset}</echo>


来源:https://stackoverflow.com/questions/1456852/how-can-i-print-a-fileset-to-a-file-one-file-name-per-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!