views:

338

answers:

1

I have some files :

  • dir/foo.txt
  • dir/bar.txt
  • dir/foobar.txt

During a apply task, I want to pass the list of file as arguments:

<target name="atask">
    <apply executable="${cmd}" parallel="false" verbose="true">
        <arg value="-in"/>
        <srcfile/>
        <arg value="dir/foo.txt"/>
        <arg value="dir/bar.txt"/>
        <arg value="dir/foobar.txt"/>

        <fileset dir="${list.dir}" includes="*.list"/>
    </apply>
</target>

This work fine, but what if I want pick the list of file dynamicly with a fileset:

<fileset dir="dir" includes="*.txt"/>

How can I convert this fileset to as many as argument in the list ? Something like:

<arg>
    <fileset dir="dir" includes="*.txt"/>
</arg>

instead of

<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>

(this example do not work because arg do not support fileset)

+4  A: 

Here's an example illustrating the use of the pathconvert task.

The converted path is passed to the executable using <arg line />.

This assumes no spaces in the paths of your *.txt files.

<target name="atask">
    <fileset dir="dir" id="myTxts">
        <include name="*.txt" />
    </fileset>
    <pathconvert property="cmdTxts" refid="myTxts" pathsep=" " />

    <apply executable="${cmd}" parallel="false" verbose="true">
        <arg value="-in" />
        <srcfile />
        <arg line="${cmdTxts}" />

        <fileset dir="${list.dir}" includes="*.list" />
    </apply>
</target>

If you might encounter spaces this should do. As above, but change (hopefully obvious which lines) to:

    <pathconvert property="cmdTxts" refid="myTxts" pathsep="' '" />

and

        <arg line="'${cmdTxts}'"/>
martin clayton
I thought It was not possible to mix <arg value= /> and <arg line= /> but it seems to be OK. This is a nice workaround and it works (I have not tested the case with spaces in the names).
Jmini