问题描述
我有一个人口稠密的文件集,我需要打印的文件名匹配到一个文本文件中。
我试过这样:
<文件集ID =myfilesetDIR =../声音>
<包括姓名=* WAV。/>
<包括姓名=* OGG。/>
< /文件集><属性名=声音REFID =myfileset/>
<回声文件=sounds.txt> $ {声音}< /回声>
它打印在一行中的所有文件,用分号隔开。我需要有每行一个文件。我怎么能做到这一点,而不诉诸调用操作系统命令或编写Java code?
更新
嗯,本来应该更具体的 - 列表中不能包含目录。我标志着ChssPly76作为公认的答案,无论如何,因为的命令是我错过了什么。剥去目录和只列出文件名,我用了。
下面是我最终的脚本:
<文件集ID =sounds_filesetDIR =../声>
<包括姓名=* WAV。/>
<包括姓名=* OGG。/>
< /文件集>&所述; pathconvert pathsep =与& #xA;财产=声音REFID =sounds_fileset>
<映射器类型=扁平化/>
< / pathconvert><回声文件=sounds.txt> $ {声音}< /回声>
使用任务:
<文件集ID =myfilesetDIR =../声音>
<包括姓名=* WAV。/>
<包括姓名=* OGG。/>
< /文件集>< pathconvert pathsep =$ {} line.separator属性=声音REFID =myfileset>
<! - 如果你想要的路径剥离添加这一点 - >
&所述;映射器>
< flattenmapper />
< /映射器>
< / pathconvert>
<回声文件=sounds.txt> $ {声音}< /回声>
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="
" property="sounds" refid="sounds_fileset">
<mapper type="flatten" />
</pathconvert>
<echo file="sounds.txt">${sounds}</echo>
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>
这篇关于如何打印文件集到一个文件,每行一个文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!