ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <>
Subject Re: Counting files in a dir
Date Tue, 05 Apr 2005 16:05:45 GMT
--- Fermin Da Costa Gomez <>
> Hi,
> What would be the best way to do the following:
> 1. Going into a directory (this is ok)
> 2. Counting the number of files of type x (getting
> files is ok, *counting* is an 
> issue)

With Ant 1.6.3 (now in beta) you could do this:

<pathconvert property="foo" pathsep="">
    <fileset dir="foo" includes="*.foo" />
  <mergemapper to="-" />

<length string="${foo}" property="foo.length" />

(look for a cooler way to do this in Ant 1.7!)

> 3. Depending on the count do something (break out of
> the target)
> Items 2. and 3. are bugging me somewhat (esp the
> counting bit in 2).
> Does anybody have a suggestion as to how i can
> accomplish this?

3. depends on what the comparison is... rather than
break out of a target, however, you are probably
better off to decompose your build so that the part
you want to skip by breaking out is in its own target,
which depends on a target that does this count-check. 
Most likely you will test its results with another
condition to set a property (or not), and whether this
property is set will determine whether the final
target is run.  Under what circumstances do you NOT
want to continue, after having counted the files? 
What actions are you trying to avoid?

> tia,
> Fermin DCG
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message