Thursday, 25 February 2016

Ant - Delete only files from directories

For an Ant build, if you just want to delete files without deleting the directory, consider the following. For illustration, we'll take the folder structure as mentioned in our earlier post.

Let's say I want to only clear the class files generated in the bin/com/ironcladzone directory.

<?xml version="1.0" encoding="UTF-8"?>

<project name="AntBuildTest" default="clean-class-files" basedir=".">

<property name="build.home" value="${basedir}" />
<property file="build.properties"/>

<target name="clean-class-files">
<delete>
<fileset dir="${bin.dir}">
<include name="**/*"/>
</fileset>
</delete>
</target>


</project>

Note : by using **/*, it will recursively delete all the files from the bin/ subdirectories. Using the <fileset> tag, we mention the directory tree, on which the delete operation needs to be performed.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker