Rob--are you using Ant 1.7?  Somehow when this first
came through I went brain dead and didn't give you the
easy answer.

<!-- condition: -->
<resourcecount count="0" refid="fs" />

Note that a pre-1.7 compatible way of testing the
number of files returned might start:

<pathconvert refid="fs" property="countme" pathsep="">
  <mergemapper to="x" />
</pathconvert>

<!-- plus condition: -->
<length length="0" string="${countme}" />

HTH,
Matt

--- "Anderson, Rob (Global Trade)"
<[EMAIL PROTECTED]> wrote:

> Thanks. This helps. We came up with a solution based
> on your input...
> 
>   <target name="main">
>     <fileset id="fs" dir="${dir}"/>
>   
>   <condition property="dir_empty">
>   <length length="0">
>     <fileset refid="fs"/>
>   </length>
>   </condition>
> 
>   <for param="file">
>     <path>
>     <fileset refid="fs"/>
>     </path>
>     <sequential>
>       <echo> This is a file: @{file}</echo>
>     </sequential>
>   </for>
> 
>   <fail unless="dir_empty">${message}</fail>
>   </target>
> 
> The length is not compared to the number of file,
> but rather the sum of
> the length of all the included file. Since we want
> the directory to be
> empty, the length we are testing for is 0. If
> someone were to test for a
> certain number of files, this would not work.
> 
> -Rob Anderson
>  
> 
> > -----Original Message-----
> > From: Bill Rich [mailto:[EMAIL PROTECTED] 
> > Sent: Friday, April 20, 2007 11:36 PM
> > To: Ant Users List
> > Subject: Re: Check if directory is empty or not
> > 
> > A little while ago Jan Materne suggested the
> following for 
> > another question about files in a directory.
> > <property name="includes"
> value="these;files;must;be;present"/>
> > <property name="includes.length" value="5"/>
> <property 
> > name="dir" value="dir"/>
> > 
> > <condition propery="all-files-present">
> >    <length length="${includes.length}">
> >        <fileset id="fs" dir="${dir}"
> includes="${includes}"/>
> >    </length>
> > </condition>
> > Can you use something similar, maybe with a * or
> **/*, and 
> > check if the length of the file list is 0?
> > HTH Bill
> > 
> > Anderson, Rob (Global Trade) wrote:
> > > I have a build.xml that runs a custom task to
> import 
> > documents into a 
> > > document management system. After the custom
> import task 
> > runs I'd like 
> > > to check the load directory for anything that
> may have been 
> > left behind.
> > > If the directory is not empty my build should
> fail.
> > >  
> > > Is there an easy way to check if a directory is
> empty or not?
> > >  
> > > Thanks in advance.
> > >  
> > >
> > > ______________________
> > > Robert Anderson
> > > Sr. System Engineer
> > > Nike - Global Trade IT
> > > 503-532-6803
> > >
> > > Never let me slip, cuz if I slip, then I'm
> slippin. - Dr. Dre
> > >
> > >  
> > >
> > >   
> > 
> > 
> >
>
---------------------------------------------------------------------
> > 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]
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to