You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Sujie <su...@yahoo.com> on 2007/10/26 10:41:33 UTC

Ant task to Count number of files in a directory

Hi

I would like to count the number of jar files in a directory. 
I am using ANT 1.7.

Any help will be much appreciated.

Thanks

-- 
View this message in context: http://www.nabble.com/Ant-task-to-Count-number-of-files-in-a-directory-tf4695926.html#a13423035
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Ant task to Count number of files in a directory

Posted by David Weintraub <qa...@gmail.com>.
I think this might help:

http://ant.apache.org/manual/CoreTasks/resourcecount.html

Here's a snippet I just tested:

        <resourcecount property="count.jars">
            <fileset dir="${jar.dir}">
                <include name="*.jar"/>
            </fileset>
        </resourcecount>
        <echo message="There are ${count.jars} jarfiles in ${jar.dir}"/>

It's much cleaner than attempting to write a script.




On 10/26/07, Sujie <su...@yahoo.com> wrote:
>
> Hi
>
> I would like to count the number of jar files in a directory.
> I am using ANT 1.7.
>
> Any help will be much appreciated.
>
> Thanks
>
> --
> View this message in context: http://www.nabble.com/Ant-task-to-Count-number-of-files-in-a-directory-tf4695926.html#a13423035
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Ant task to Count number of files in a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de] 
Sent: Friday, October 26, 2007 12:19 PM
To: Ant Users List
Subject: RE: Ant task to Count number of files in a directory

/*
...

you need =

http://jakarta.apache.org/bsf/
http://dist.codehaus.org/jruby/jruby-complete-1.0.1.jar

*/


also use =
<scipt language="ruby">
<![CDATA[
$project.setProperty "filecount", Dir["Y:/temp/**/*.jar"].length.to_s
]]>
</script>

because the second parameter of the setProperty() method
has to be a string


Regards, Gilbert


---------------------------------------------------------------------
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


RE: Ant task to Count number of files in a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi, 


-----Original Message-----
From: Sujie [mailto:sujie_19@yahoo.com] 
Sent: Friday, October 26, 2007 12:09 PM
To: user@ant.apache.org
Subject: RE: Ant task to Count number of files in a directory

/*
I get the following error when trying to using ruby as a script
language. 
"unable to load a script engine manager (org.apache.bsf.BSFManager or
javax.script.ScriptEngineManager)"
Do i need to import something else?

The resource count is not working for me. It always returns 1
irrespective
of number of files in the directory.
<resourcecount property="uninstall-files">
  <filelist dir="${installDir}/uninstall" files="*.jar" />
</resourcecount>
<echo message="count of files ${uninstall-files}" />
*/

you need =

1. the BeanScriptingFramework (bsf.jar) as for
    all other scripting languages (groovy,javascript,
    beanshell ...), get it here =
    http://jakarta.apache.org/bsf/

2. http://dist.codehaus.org/jruby/jruby-bin-1.0.1.zip, the contained
    jruby.jar  will be sufficient for your code snippet, but if you need
    more ruby libraries then use 
   http://dist.codehaus.org/jruby/jruby-complete-1.0.1.jar
   then you could use those libraries with  'require ...' (like import
in java)
   if in doubt use the complete jar

simply put those jars into %ANT_HOME%/lib and you're ready
to go

Regards, Gilbert


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Ant task to Count number of files in a directory

Posted by Sujie <su...@yahoo.com>.
I get the following error when trying to using ruby as a script language. 
"unable to load a script engine manager (org.apache.bsf.BSFManager or
javax.script.ScriptEngineManager)"
Do i need to import something else?

The resource count is not working for me. It always returns 1 irrespective
of number of files in the directory.
<resourcecount property="uninstall-files">
  <filelist dir="${installDir}/uninstall" files="*.jar" />
</resourcecount>
<echo message="count of files ${uninstall-files}" />

Any idea what is the error.

Thanks


Rebhan, Gilbert wrote:
> 
>  
> 
> -----Original Message-----
> From: Sujie [mailto:sujie_19@yahoo.com] 
> Sent: Friday, October 26, 2007 10:42 AM
> To: user@ant.apache.org
> Subject: Ant task to Count number of files in a directory
> 
> /*
> Hi
> 
> I would like to count the number of jar files in a directory. 
> I am using ANT 1.7.
> */
> 
> with ant < 1.7
> 
> <script language="ruby">
> <![CDATA[
> $project.setProperty "yourproperty", Dir["C:/your/path/**/*.jar"].length
> ]]>
> </script>
> 
> use your/path/**/*.jar if you want to search recursive,
> otherwise use /*.jar
> 
> ${yourproperty} contains number of jars
> 
> 
> with ant => 1.7
> see manual coretasks / resourcecount
> 
> 
> Regards, Gilbert
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Ant-task-to-Count-number-of-files-in-a-directory-tf4695926.html#a13424198
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Ant task to Count number of files in a directory

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Sujie [mailto:sujie_19@yahoo.com] 
Sent: Friday, October 26, 2007 10:42 AM
To: user@ant.apache.org
Subject: Ant task to Count number of files in a directory

/*
Hi

I would like to count the number of jar files in a directory. 
I am using ANT 1.7.
*/

with ant < 1.7

<script language="ruby">
<![CDATA[
$project.setProperty "yourproperty", Dir["C:/your/path/**/*.jar"].length
]]>
</script>

use your/path/**/*.jar if you want to search recursive,
otherwise use /*.jar

${yourproperty} contains number of jars


with ant => 1.7
see manual coretasks / resourcecount


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org