How to check if directory exists before deleting it, using ANT?

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.

    <target name="clean" description="clean">
        <delete dir="${build}" failonerror="false"/>
        ....
        <delete dir="${report}" failonerror="false"/>
    </target>

This is useful if you don’t want to install ant-contrib or can’t for some reason.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)