如何将文件集打印到文件中,每行一个文件名? [英] How can I print a fileset to a file, one file name per line?

查看:19
本文介绍了如何将文件集打印到文件中,每行一个文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个填充的文件集,我需要将匹配的文件名打印到文本文件中.

I have a populated fileset and I need to print the matching filenames into a text file.

我试过了:

<fileset id="myfileset" dir="../sounds">
    <include name="*.wav" />
    <include name="*.ogg" />
</fileset>

<property name="sounds" refid="myfileset" />
<echo file="sounds.txt">${sounds}</echo>

将所有文件打印在一行上,用分号分隔.我需要每行一个文件.如何在不求助于调用操作系统命令或编写 Java 代码的情况下执行此操作?

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?

更新:

啊,应该更具体 - 列表不能包含目录.无论如何,我将 ChssPly76 标记为已接受的答案,因为 pathconvert 命令正是我错过了什么.为了去除目录并仅列出文件名,我使用了 "flatten" 映射器.

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>

推荐答案

使用 PathConvert 任务:

<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>

这篇关于如何将文件集打印到文件中,每行一个文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆