Ant target to remove old build directories
I have my builds published to the directories like:
/some/dir/build-1/
/some/dir/开发者_JAVA百科build-2/
/some/dir/build-3/
...
/some/dir/build-n/
I need ant task to delete all the previous build directories except the last three (n, n-1 and n-3).
I suppose I shuould use<delete>
task, but how to configure the attributes?Make use of resources. When empty and non empty directories are mixed up, i believe you have to use a mix of fileset and dirset to make it work with selectors, because delete in combination with selectors and fileset won't work for empty directories.Whereas if you have only nonempty directories you may use the fileset part only - here's a snippet using some sort + date selector, deleting the latest 3 directories =
<project name="foo">
<delete includeEmptyDirs="true" verbose="true">
<last count="3">
<sort>
<date/>
<fileset dir="/some/dir">
<include name="**/*build*/**" />
</fileset>
</sort>
</last>
</delete>
<delete verbose="true">
<last count="3">
<sort>
<date/>
<dirset dir="/some/dir">
<include name="**/*build*/**" />
</dirset>
</sort>
</last>
</delete>
</project>
see Ant Manual/Resources for further details..
精彩评论