cmcculloh
cmcculloh

Reputation: 48603

Ant concat fileset separator

When using concat with fileset in Ant, how do I make an action happen for each element in the fileset. Such as, adding a string:

<fileset dir="${project.path.scripts-library}"
                excludes="!*.js, **/*.bak, **/dev.*"
>
    <type type="file" />
    <include name="**/0*.js" />
    <include name="**/1*.js" />
    <string>test</string>
</fileset>

Or echoing the current file name for each file in the fileset (and, how do I GET the file name for the current file???):

<fileset dir="${project.path.scripts-library}"
                excludes="!*.js, **/*.bak, **/dev.*"
>
    <echo file="${app.path.file}" 
            append="true"
            message=",${the.file.name}" />

    <type type="file" />
    <include name="**/0*.js" />
    <include name="**/1*.js" />
</fileset>

Upvotes: 5

Views: 2895

Answers (1)

Ivan Nevostruev
Ivan Nevostruev

Reputation: 28723

I think there is no such thing in default ant. The closest one is <apply>, but it's system specific:

<apply executable="echo"> <!-- run this command with each file name -->
  <fileset dir="/tmp" includes="**/*.*"/>
</apply>

Also you can install ant-contrib to enable <for> task:

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<for param="file">
  <path>
    <fileset dir="/tmp" includes="**/*.*"/>
  </path>
  <sequential> <!-- run any task here -->
    <echo>file [@{file}]</echo>
  </sequential>
</for>

Upvotes: 4

Related Questions