如何在Ant任务中加载文件列表作为资源?

And*_*vic 3 ant filelist

我在网上看到了如何加载包含空格但尚未存在Ant任务的文件列表.

我有一个文件,每行包含一个文件路径,如下所示:

dir1/dir2/dir with spaces/file1.js
dir1/dir2/dir with spaces/dir3/file2.js
dir1/file1.js
Run Code Online (Sandbox Code Playgroud)

由于路径有空格我不能使用:

<filelist files="..." />
Run Code Online (Sandbox Code Playgroud)

这些文件还不存在,所以似乎我无法使用

<fileset>
    <includesfile name="..." />
</fileset>
Run Code Online (Sandbox Code Playgroud)

任何想法都会受到很大的影响.

mar*_*ton 5

您可以使用资源列表.例如,如果您的文件列表位于名为"files.txt"的文件中:

<resourcelist id="files">
    <file file="files.txt"/>
</resourcelist>

<touch mkdirs="true">
    <resources refid="files" />
</touch>
Run Code Online (Sandbox Code Playgroud)

对我来说,这会产生:

[touch] Creating .../filelist/dir1/dir2/dir with spaces/file1.js
[touch] Creating .../filelist/dir1/dir2/dir with spaces/dir3/file2.js
[touch] Creating .../filelist/dir1/file1.js
Run Code Online (Sandbox Code Playgroud)

这样做的原因是,<resourcelist>将文件中的每一行视为一个单独的资源,因此行分隔符而不是逗号或空格分隔项.