简体   繁体   中英

Recursively deleting all files of one type using Ant

在ant构建脚本中,如何删除一个目录及其子目录中的所有*.java文件?

It's slightly unclear how deep in the directory tree you would like to delete the .java files. I'll provide ways to do both.

Full recursive delete

Recursively deletes all .java files anywhere under the provided target directory.

<delete>
    <fileset dir="${basedir}/path/to/target/directory" includes="**/*.java"/>
</delete>

Only within the target directory and its immediate child directories

Deletes .java files in the specified target directory, and in any directories that are immediate children of the target directory, but no further.

<delete>
    <fileset dir="${basedir}/path/to/target/directory" includes="*.java,*/*.java"/>
</delete>

For additional options, have a look at the documentation for the delete task.

Be careful - If you put the wrong directory in for your target directory, you might delete things you don't want to. Consider making the paths to your target dir relative to the build file, or to ${basedir} .

<delete>
<fileset dir="." includes="**/*.java"/>
</delete>

The above delete task deletes all files with the extension .java from the current directory and any subdirectories.

<delete>    
    <filename name="**/*.java"/>
</delete>

http://ant.apache.org/manual/Types/fileset.html

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