ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wayne Cannon <wcan...@turinnetworks.com>
Subject Re: Delete the contents of a directory but not the directory itself
Date Mon, 15 Jan 2007 16:07:55 GMT
I experienced the same problem and had the same question.

However, I like the suggestions presented here and feel that they are 
more consistent with the behavior of operating systems and file-system 
libraries.  For example, you don't expect "rm -r mydir" or "rmdir mydir" 
to provide a parameter to delete all of the contents and leave the 
directory -- you use "rm -r mydir/*" or "rmdir mydir\*", instead.

I'm relatively new to ant and not yet completely comfortable with its 
wild card notation "**/*", "*/**", etc., which probably led me to look 
initially for an alternative approach and the same question you 
initially raised.

Regards,
Wayne


Daffin, Miles (IT) wrote:
> Folks,
>
> Does anyone think that this is a legitimate problem with the way delete
> functions (it is not consistent) or am I just missing 'the point'?  
>
> Cordially,
>
> Miles
>
>   
>> -----Original Message-----
>> From: Daffin, Miles (IT) 
>> Sent: Friday 12 January 2007 22:46
>> To: Ant Users List
>> Subject: RE: Delete the contents of a directory but not the 
>> directory itself
>>
>> And to me. I assumed that when using delete with no dir 
>> attribute and a nested fileset would not include the base 
>> dir. After all, if one uses a fileset in the context of a 
>> copy this is what happens. Take this build as proof:
>>
>> <project name="test" basedir="." default="all">
>>   <property name="tmp.dir" value="tmp"/>
>>   <property name="from.dir" value="${tmp.dir}/fromdir"/>
>>   <property name="to.dir" value="${tmp.dir}/todir"/>
>>   <macrodef name="setup">
>>     <sequential>
>>       <delete dir="${tmp.dir}"/>
>>       <mkdir dir="${from.dir}/dir1"/>
>>       <mkdir dir="${from.dir}/dir2"/>
>>       <touch file="${from.dir}/file1.txt"/>
>>       <touch file="${from.dir}/file2.txt"/>
>>     </sequential>
>>   </macrodef>
>>   <target name="test-fileset-copy">
>>     <setup/>
>>     <copy todir="${to.dir}" includeemptydirs="true">
>>       <fileset dir="${from.dir}"/>
>>     </copy>
>>     <available file="${to.dir}/fromdir" property="test.failed"/>
>>     <fail if="test.failed" message="fromdir copied to todir"/>
>>   </target>
>>   <target name="test-fileset-delete">
>>     <setup/>
>>     <delete includeemptydirs="true">
>>       <fileset dir="${from.dir}"/>
>>     </delete>
>>     <available file="${from.dir}" property="test.success"/>
>>     <fail unless="test.success" message="fromdir deleted!"/>
>>   </target>
>>   <target name="all" depends="test-fileset-copy, 
>> test-fileset-delete"/> </project>
>>
>> I think that the way delete behaves here is wrong.
>>
>>     
>>> -----Original Message-----
>>> From: Dominique Devienne [mailto:ddevienne@gmail.com]
>>> Sent: Friday 12 January 2007 20:47
>>> To: Ant Users List
>>> Subject: Re: Delete the contents of a directory but not the 
>>>       
>> directory 
>>     
>>> itself
>>>
>>>       
>>>> Explicitly saying includes="**/*" literally means only 
>>>>         
>> any file or 
>>     
>>>> directory below the basedir of the fileset.  Note that we
>>>>         
>>> welcome any
>>>       
>>>> suggestions regarding where in the manual you might have
>>>>         
>>> hoped to find
>>>       
>>>> this file scanning information.
>>>>         
>>> This thread picked my interest, because I didn't know the answer ;-)
>>>
>>> I personally assumed no includes was equivalent to "**/*", which I 
>>> would have guessed to include the base dir, when it doesn't.
>>>
>>> I would have tried "*/**", which I would interpret as: all files 
>>> directly in the base dir, and any sub-directories of those. 
>>>       
>> This also 
>>     
>>> parallels the fact that * in unix shells does not match ., 
>>>       
>> the "base 
>>     
>>> dir".
>>>
>>> All that to say that having to use "**/*" instead of "*/**" 
>>> feels counter-intuitive to me ;-) --DD
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>>     
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>>>       
>> additional 
>>     
>>> commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>       
>> --------------------------------------------------------
>>
>> NOTICE: If received in error, please destroy and notify 
>> sender. Sender does not intend to waive confidentiality or 
>> privilege. Use of this email is prohibited when received in error.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>> additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>     
> --------------------------------------------------------
>
> NOTICE: If received in error, please destroy and notify sender. Sender does not intend
to waive confidentiality or privilege. Use of this email is prohibited when received in error.
>
> ---------------------------------------------------------------------
> 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