tags:

views:

28

answers:

1

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 just "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?

+1  A: 

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.

skaffman
Works perfectly. Thanks very much! :)
Benjamin