Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top