ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Delaney" <mdela...@upromise.com>
Subject Re: Delete N directories that match a regexp
Date Fri, 27 Mar 2009 20:25:42 GMT
I tried you're advice below, to the best of my understanding of it and I 
seem to have taken a step in the wrong direction. Now, nothing happens ...

I already have a shell script ready, I'm wondering if that's the way I 
should go.

Matt Benson wrote:
> 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)w
>   <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 <mdelaney@upromise.com> wrote:
>
>   
>> From: Michael Delaney <mdelaney@upromise.com>
>> Subject: Delete N directories that match a regexp
>> To: "Ant Users List" <user@ant.apache.org>
>> 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: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>     
>
>
>       
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   

Mime
View raw message