简体   繁体   English

使用Ant递归删除一种类型的所有文件

[英]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. 稍微不清楚您希望删除.java文件的目录树有多深。 I'll provide ways to do both. 我会提供两种方法。

Full recursive delete 完全递归删除

Recursively deletes all .java files anywhere under the provided target directory. 递归删除提供的目标目录下任何位置的所有.java文件。

<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. 删除指定目标目录中的.java文件,以及目标目录的直接子目录中的任何目录,但不再删除.java文件。

<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} . 考虑相对于构建文件或${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. 上面的删除任务从当前目录和所有子目录中删除扩展名为.java的所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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