Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 852
tyrondis Avatar asked Oct 19 '10 08:10

tyrondis


People also ask

Is there a way to erase all files in the current directory including all its subdirectories using only one command?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r .

Which one is true code for delete the directory in ant?

This task is used to delete a single file, directory or subdirectories. We can also delete set of files by specifying set of files. It does not remove empty directory by default, we need to use includeEmptyDirs attribute to remove that directory.

Which method is used to delete all files in a directory?

You can use the FileUtils. cleanDirectory() method to recursively delete all files and subdirectories within a directory, without deleting the directory itself. To delete a directory recursively and everything in it, you can use the FileUtils.

Which choice will delete a directory and all subdirectories C#?

To delete the specified directory and all its subdirectories, use the Directory. Delete() method.


1 Answers

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.

like image 89
skaffman Avatar answered Oct 19 '22 03:10

skaffman