Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
AW: Count number of files in fileset

AW: Count number of files in fileset

2005-06-14       - By Jan.Materne@(protected)

You could count the files with

<scriptdef name="count" language="javascript">
   <attribute name="property"/>
   <element name="fileset" type="fileset"/>
   <![CDATA[
       filesets = elements.get("fileset");
       propname = attributes.get("property");
       number = 0;

       for (i = 0; i < filesets.size(); ++i) {
           number = number + filesets.get(i).getDirectoryScanner(project)
.getIncludedFiles().length;
       }

       project.setProperty(propname, number);
   ]]>
</scriptdef>



<count property="c1">
   <fileset dir="."/>
</count>
<echo>All files here  : ${c1}</echo>



> I have to concat some files from a fileset together into another file.
> However, this only should hebben if the number of files in fileset
> module-webservices-config-fileset > 0.

What do you expect with 'module-webservices-config-fileset = 0'? You could
<copy>/<echo> a
"zero-file" in that case.


Jan


>-----Urspr?ngliche Nachricht-----
>Von: Dominique Devienne [mailto:ddevienne@(protected)]
>Gesendet: Montag, 13. Juni 2005 21:49
>An: 'Ant Users List'
>Betreff: RE: Count number of files in fileset
>
>> In 1.6 you could use the ${toString:} psuedo-property:
>>   <target name="present">
>>     <fileset id="fileset.notpresent" dir="."
>>              includes="*.notpresent"/>
>>     <condition property="no.files.present">
>>       <equals arg1="" arg2="${toString:fileset.notpresent}"/>
>>     </condition>
>>     <echo>no.files.present=${no.files.present}</echo>
>>     <fileset id="fileset.present" dir="."
>>              includes="*.xml"/>
>>     <condition property="no.files.present_2">
>>       <equals arg1="" arg2="${toString:fileset.present}"/>
>>     </condition>
>>     <echo>no.files.present_2=${no.files.present_2}</echo>
>>   </target>
>
>You can check a fileset is empty using the above, but not
>count the number
>of files. For that you'd need custom code, in Java or in a <script>.
>
>Note that ${toString:referenceId} is still a bit experimental.
>
>Using <property name="foo" refid="referenceId" /> is more
>traditional (but
>Ant 1.6 specific), and for older versions of Ant, use <pathconvert> to
>convert the fileset into a string. --DD
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@(protected)
>For additional commands, e-mail: user-help@(protected)
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.