AwesomeBrownGuy
AwesomeBrownGuy

Reputation: 43

Ant task to write all file names in a directory to a txt file?

I need to write an ant task that goes into the resources directory and writes all the files names to a txt file in the resources directory. Is this possible? Any help would be greatly appreciated.

Upvotes: 1

Views: 689

Answers (1)

CAustin
CAustin

Reputation: 4614

You can use the pathconvert and echo tasks for this. Here's an example target:

<target name="generate-file-list">
    <delete dir="testdir" />

    <mkdir dir="testdir" />
    <mkdir dir="testdir/subdir" />

    <touch file="testdir/file1" />
    <touch file="testdir/file2" />
    <touch file="testdir/file3" />
    <touch file="testdir/subdir/file4" />

    <pathconvert property="testdir.files" pathsep="${line.separator}">
        <fileset dir="testdir" />
    </pathconvert>

    <echo file="filelist.txt" message="${testdir.files}" />
</target>

Output in filelist.txt:

/home/user/test/testdir/file1
/home/user/test/testdir/file2
/home/user/test/testdir/file3
/home/user/test/testdir/subdir/file4

Upvotes: 3

Related Questions