Using ANT
, how can i make sure that directory exists before attempting to remove it?
As part of my current clean task, i
<target name="clean" description="clean">
<delete dir="${build}" />
<delete dir="${bin}" />
<delete dir="${dist}/myrunner.${version}.jar" />
<delete dir="${doc}" />
<delete dir="${report}" />
</target>
This works well, however (obviously) remove happens when there is something to remove.
Using ANT
, how can i check if directory exist?
Nice and clean solution below: Using ant-contribs.jar
When using this solution, be sure to put the following line on top
with vanilla ant you would use something like =
else see = Ant check existence for a set of files
for a similar question
Here is the answer :
You can do it by ordering to delete a list of files with names equal to the name you need. It is much easier and direct than to create a special target. And you needn't any additional tools, just pure Ant.
http://ant.apache.org/manual/Types/fileset.html
Check out the available task.
Here's a similar question.
Do I have a way to check the existence of a directory in Ant (not a file)?
For this specific case, I'm not going to answer the question "how to find if a directory exists", because that's already been answered, but I'm just going to point out that in your clean task you can use
failonerror="false"
to keep the ant task from exiting. This should be suitable in a clean task because if there's nothing to clean, it should not be a problem.This is useful if you don't want to install ant-contrib or can't for some reason.