Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a list of files as resources in an Ant task?

Tags:

ant

filelist

I've looked all over the net as to how I can load a list of files that contain spaces and don't yet exist with an Ant task.

I have a file that contains one file path per line, like so:

dir1/dir2/dir with spaces/file1.js
dir1/dir2/dir with spaces/dir3/file2.js
dir1/file1.js

Since the paths have spaces I cannot use:

<filelist files="..." />

The files also don't exist yet, so it seems like I can't use

<fileset>
    <includesfile name="..." />
</fileset>

Any ideas would be greatly appreaciated.

like image 328
Andrej Pavlovic Avatar asked Sep 18 '25 18:09

Andrej Pavlovic


1 Answers

You can use a resourcelist for this. For example, if your list of files are in a file called 'files.txt':

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

<touch mkdirs="true">
    <resources refid="files" />
</touch>

For me this yields:

[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

The reason this works is that a <resourcelist> treats each line in the file read as a separate resource, so line separators rather than commas or spaces divide the items.

like image 75
martin clayton Avatar answered Sep 22 '25 16:09

martin clayton