ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: Count copied files
Date Mon, 01 Aug 2005 06:07:51 GMT
Not that I am aware of.

AFAIK there is no <count><fileset/></count>.
Ant 1.7 will include "Resources" [1] (e.g. <fileset> will be one) and then there will
be a 
<resourcecount> task.

ATM I get the idea of a counting selector ...
When processing a fileset the underlying DirectoryScanner asks all nested selectors (like
<modified/>) if they would select that file. So the selector is asked for each file.
A new
selector could simply increase a number (stored in a property file). You could write that
selector via <scriptselector> [2] - oh, <scriptselector> is introduced with 1.7,
so you have
to write that in Java.

But that would only count the number of selected files - <copy> does a filecheck for
its own
(like many other tasks). And you dont get that info.
Well, when using <copy overwrite="true"/> you switch off exactly that filecheck, and
maybe with
<uptodate> you could get some of the idea behind overwrite="false".

Maybe could extend <copy> by extending oata.taskdefs.Copy [3] and overriding one method
(it logs exactly that info to STDOUT):

protected void doFileOperations() {
    writeToPropFile( fileCopyMap.size() );
protected void writeToPropFile(int numberOfCopiedFiles) {
    // write to propfile

Mmmh ... seeing that .... maybe a <record> around the <copy> would do that ...

I┬┤ll do a little test ...

Yep - and tested with Ant 1.6.3 and 1.7 :-)

  How to get the number of copied files into a property?

    <!-- prepare the target directory -->
    <mkdir dir="to"/>

    <!-- start logging to file -->
    <record name="" action="start"/>

    <!-- Let 'copy' do its job -->
    <copy todir="to">
        <fileset dir="from"/>

    <!-- stop writing to log file -->
    <record name="" action="stop"/>

    <!-- convert the log message to a property-file -->
    <replaceregexp file="" match=".*Copying (.*) file.*" replace="nr=\1"/>

    <!-- read that file, handle zero-files-copied special case (empty file created) -->
    <property file=""/>
    <property name="nr" value="0"/>

    <!-- use that property -->
    <echo message="Copied files: ${nr}"/>




>-----Urspr├╝ngliche Nachricht-----
>Von: KrustyDerClown [] 
>Gesendet: Samstag, 30. Juli 2005 22:29
>Betreff: Count copied files
>i have the following copy task:
><target name="copy">
> <copy todir="${dest.dir}" overwrite="true">
>     <fileset dir="${outputDir}">
>      <include name="log_*.xml"/>
>     </fileset>
> </copy>
>Can i count the files which are copied and write this number 
>to a property ?
>Thank you for answers.
>Greets Oliver 
>To unsubscribe, e-mail: For 
>additional commands, e-mail:

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

View raw message