# ant-user mailing list archives

##### Site index · List index
Message view
Top
From Francis GALIEGUE <...@one2team.com>
Subject Re: Another options
Date Tue, 11 Aug 2009 18:57:35 GMT
On Tue, Aug 11, 2009 at 16:20, Redondo Gallardo, Raul
Maria<rmredondo@eservicios.indra.es> wrote:
> Well, I'll try it:
>
> For example: In a main folder C: with different subfolders structure I need to find the
folder(s) which contain the file with name filev2.txt. After I must to copy all the files
of this directory to another folder and launch a java program from ANT. Is this possible?.
>
> For example:
>
> It exist the structure of folders:
> C:\home\folder01\file.txt
> C:\home\folder01\file2.txt
> C:\Work\folder10\folder20\fileA.txt
> C:\Work\folder10\folder20\fileB.txt
> C:\Work\folder10\folder20\fileC.txt
> C:\Work\folder10\folder20\filev2.txt
> C:\Mom\folder40\folder50\fileA.txt
> C:\Mom\folder40\folder50\fileB.txt
> C:\Mom\folder40\folder50\filev2.txt
> C:\happy\file.txt
>
> I must to find in C: the folders which contains the file filev2.txt and copy the files
into the same folder to another path and launch a java program.
>
> When I use fileset, I obtain:
> C:\Work\folder10\folder20\filev2.txt; C:\Mom\folder40\folder50\filev2.txt
>
> With this I would want to do:
> 1.- Split the line in two (C:\Work\folder10\folder20\filev2.txt and
>    C:\Mom\folder40\folder50\filev2.txt)
>
> 2.- Obtain the path of the first substring (C:\Work\folder10\folder20)
>
> 3.- Copy the all the files which exists into this folder to D:\process
>
> 4.- Launch a file .bat that works with this files
>
>
> These are the four steps which I need, the step number 4 I have solved, but the steps
1, 2 and 3, I've no idea if is it possible to do with ANT.
>
>
>
> Do you understand the example? Is it possible to do this?
>
> Thank you very very much.
>
> Best regards.
>
> PS: If you think that exist an easy way to do this, tell me, because the steps are not
fixed, they are the way which I think would be a solution, but it's possible that I'm wrong.
>

It is possible, either with or without the split. Here is a solution
without the split, which makes use of ant-contrib (yes, I just cannot
work without it, it's too powerful to be ignored imho). Of course,
you'll have to adapt it to what your script expects as an argument,
whether the build should fail if the script fails, etc (and note that
ant-contrib also has try/catch).

Note that while <dirname> looks great, it has a huge drawback: its
output is a property, and properties are immutable. At least, they're
immutable with ant 1.6.x, I don't know for ant 1.7.x.

<macrodef name="domystuff">
<attribute name="directory"/>
<sequential>
<copy todir="D:\process">
<fileset dir="@{directory}" includes="*"/>
</copy>
<exec executable="C:\path\to\the.bat"/>
<delete>
<fileset dir="D:\process" includes="*"/>
</delete>
</sequential>
</macrodef>

<target name="doit">
<for param="directory">
<dirset dir="c:" includes="**/*"/>
<sequential>
<if>
<available file="@{directory}.filev2.txt" type="file"/>
<then>
<domystuff directory="@{directory}"/>
</then>
</if>
</sequential>
</for>
</target>

--

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org