Delete all files in a directory w/o subdirectories with Apache Ant
I need an Apache Ant target that deletes all files in a directory but does not touch subdirectories.
In my current approach I have to explicitly name the subdirectories I want to skip (atm jus开发者_StackOverflow中文版t "src/").
<delete>
<fileset dir="${dist.dir}" excludes="src/" />
</delete>
But I don't like it. That way I would have to modify the target everytime something changes in the subdirectory structure.
Any ideas?
This should work:
<delete>
<fileset dir="${dist.dir}">
<include name="*"/>
</fileset>
</delete>
The *
wildcard should only delete the files at the top level, not directories or subdirectories. If you wanted it to be recursive, you'd need to use **/*
instead.
精彩评论