ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: Ant- copy file from one folder to many folders
Date Mon, 29 Dec 2008 09:28:46 GMT


-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com]
Sent: Monday, December 29, 2008 6:10 AM
To: Ant Users List; Alexei Alexei
Subject: Re: Ant- copy file from one folder to many folders

/*

The standard <copy> task requires a single target name, so you
couldn't do it with the standard Ant tasks. However, there is a
special addition to Ant called the AntContrib tasks
<http://ant-contrib.sourceforge.net/>. These extend Ant to allow for
all sorts of tricks.

There's one special AntContrib task called <foreach>
<http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html>. This
will allow you to go through each directory in a list, and use that as
the "todir" parameter of a copy task. It'll look something like this:

<target name="orig">
    <foreach
        target="copyclass"
        parameter="copy.target">
        <path>
             <dirset dir="myfolder*/**"/>
        </path>
    </foreach>
</target>

<target name="copy">
    <copy todir="${copy.target}"
        file="myclass.class"/>
</target>

READ THE COMPLETE DOCUMENTATION ON THE ANT-CONTRIB PACKAGE! You must
download the AntContrib JAR file, put it in your Ant's "lib"
directory, and add a <taskdef> task to your build.xml file.

*/

Better use <for> instead of <foreach>, as foreach opens a new project scope
for every target execution.

Also with <for> there's no need for an extra target.
So with a given structure like that =

c:\test>tree /A /F
C:.
+---myfolder1
|       myclass.class
|
\---myfolder2
    |   myclass.class
    |
    +---test
    |   |   myclass.class
    |   |
    |   \---test2
    |           myclass.class
    |
    \---test3
            myclass.class

you can use =

<project name="foobar" default="main" basedir=".">

<!-- // Taskdefs -->
<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- Taskdefs // -->

<target name="main">
 <for param="dir">
  <dirset dir="C:/test" includes="**"/>
   <sequential>
    <copy todir="@{dir}" overwrite="true" verbose="true">
     <fileset dir="C:/test/myfolder1" includes="myclass.class" />
    </copy>
   </sequential>
 </for>
</target>

</project>


btw Alexei =
your given situation was a bit irritating to me, as the file myclass.class is
already existent in all directories, including the one you want to copy from
(myfolder1 in your example).
i understood it like that = a new myclass.class drops in myfolder1 and you
need to spread it recursive in all subdirectories, right !?


Regards, Gilbert

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


Mime
View raw message