exec a command on each file in a phing target
Asked Answered
K

2

7

How can I execute a target action in phing on each file of a fileset target? For example:

<exec command="cat {$filepath}">
  <fileset dir=".">
    <include name="*.php">
  </fileset>
</exec>
Kinney answered 13/5, 2010 at 14:27 Comment(0)
T
8

You can use the foreach task with filesets, e.g.:

<?xml version="1.0" encoding="utf-8"?>
<project name="cat-fileset" basedir="." default="iterate">
    <target name="iterate">
        <foreach param="fname" absparam="abs-fname" target="cat">
            <fileset dir="${project.basedir}">
                <include name="*.php" />
            </fileset>
        </foreach>
    </target>    
    <target name="cat">
        <exec command="cat ${abs-fname}" 
            escape="false"
            checkreturn="true"
            passthru="true" />
    </target>
</project>

Note that this feature was implemented in version 2.4.0 of Phing

Tuna answered 1/6, 2010 at 19:14 Comment(2)
this is my phing version: Phing version 2.3.3 I got this error: Error initializing nested element <fileset> [wrapped: phing.tasks.system.ForeachTask doesn't support the 'fileset' creator/adder.]]Kinney
Sorry for that, it's not 2.3.1 but 2.4.0: phing.info/trac/ticket/252 Latest stable version is 2.4.1, you may want to upgrade.Tuna
C
1
<apply executable="cat" parallel="false">
  <fileset dir=".">
    <include name="*.php">
  </fileset>
</apply>
Clinandrium answered 3/3, 2015 at 5:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.