简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM