Glad to know you're using the resourcecollection stuff in anger and getting 
some mileage out of it.  Unfortunately it seems you've hit on a genuine lack... 
:)  Firstly your date-sorted resourcecollection should be a dirset, but then 
you still need a decent way to round up the children of those directories.  The 
easiest way would be to use antcontrib's <for> task to iterate over the 
directories and delete each:

(given dirset id=ds and antcontrib ns ac)
<ac:for param="d">
  <dirset refid="ds" />
  <sequential>
    <delete dir="@{ds}" />
  </sequential>
</ac:for>

However, you said stock Ant.  I was stumped, and was about to write that you 
could drop back to scripting or write a Java task or type (such a type might be 
nice).  Then my younger, more inventive self barged in, gave me a good smack, 
and came up with this approach:

(given same dirset id=ds)
  <pathconvert refid="ds" property="includes" pathsep="${line.separator}">
    <regexpmapper from="(^.*$)" to="\1${file.separator}**" />
  </pathconvert>
  <echo file="includesfile">${includes}</echo>
  <delete>
    <files includesfile="includesfile" />
  </delete>
  <delete file="includesfile" />

Note that if you know that your directories won't have spaces or commas in 
their names you could bypass the includesfile and simply

<delete>
  <files includes="${includes}" />
</delete>

--oh, except in this case you'd use pathsep="," on your pathconvert.

Whaddya think?

-Matt

--- On Thu, 3/26/09, Michael Delaney <[email protected]> wrote:

> From: Michael Delaney <[email protected]>
> Subject: Delete N directories that match a regexp
> To: "Ant Users List" <[email protected]>
> Date: Thursday, March 26, 2009, 1:09 PM
> I'm look for a way, with using ant
> "out of the box", to find a list of directories and sort
> them via date then deleted the oldest three directories.
> 
> Thus far I've been able to sort the directories, take the
> last three but I can't seem to figure out how to delete the
> actual directory; see attached build.xml for an example of
> how far I've gotten.
> 
> -----Inline Attachment Follows-----
> 
> <project name="project-deletion" default="build">
>     <property name="base.dir"
> value="/srv/jboss" />
>     <property name="module.name"
> value="myProject" />
> 
>     <target name="build">
>         <antcall target="clean"
> />
>     </target>
> 
>     <target name="get-count">
>         <condition
> property="should.clean">
>             <resourcecount
> when="greater" count="8">
>                
> <fileset dir="${base.dir}">
>                
>     <include
> name="*-${module.name}/prefix.properties" />
>                
> </fileset>
>            
> </resourcecount>
>         </condition>
>     </target>
> 
>     <target name="clean" depends="get-count"
> if="should.clean">
>         <delete
> includeemptydirs="true">
>             <first
> count="3">
>                
> <sort>
>                
>     <fileset dir="${base.dir}">
>                
>         <include
> name="*-${module.name}/*" />
>                
>     </fileset>
>                
>     <date
> xmlns="antlib:org.apache.tools.ant.types.resources.comparators"
> />
>                
> </sort>
>             </first>
>         </delete>
>     </target>
> 
> </project>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to