Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant task to delete files and directory that start with the same name

Tags:

ant

In my folder example

I have a directory called test. It contains many subfolders I also have files called test.properties and test.properties.sample

I am trying to create an ant script to remove the files and directory

Do I have to have 3 different tasks to delete these files?

For example

<delete dir="test" />
<delete file="test.properties" />
<delete file="test.properties.sample" />

I would rather have something like

<delete dir="test*" />

so it deletes everything in the folder that starts with test

like image 204
Decrypter Avatar asked Jun 28 '13 21:06

Decrypter


People also ask

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

For historical reasons <delete dir="x"/> is different from <delete><fileset dir="x"/></delete> ; it will try to remove everything inside x including x itself, not taking default excludes into account, blindly following all symbolic links. If you need more control, use a nested <fileset> .

Which method is used to delete a directory DEL ()?

remove() method in Python is used to remove or delete a file path.

What is the name of the command used to delete files from a directory?

Use the rm command to remove files you no longer need. The rm command removes the entries for a specified file, group of files, or certain select files from a list within a directory.


1 Answers

Use a fileset to select files with a pattern, a dirset to select directories with a pattern.

This should do the job:

<delete>
    <dirset dir="${basedir}" includes="test*" />
    <fileset dir="${basedir}" includes="test*" />
</delete>
like image 59
Nicolas Lalevée Avatar answered Sep 16 '22 13:09

Nicolas Lalevée