Search code examples
antant-contrib

ant iterate inside a folder


I tried to get the files name of a folder using the following script

   <target name="test1" depends ="init">
       <fileset id="appendJars" dir="${ant.dir}/test">
        <include name="*.txt" />
    </fileset>
    <pathconvert property="files" refid="appendJars" pathsep="," />

    <echo message="files: ${files}"  />
    <for list="${files}" param="f">

        <sequential>
        <echo>@{f}</echo>
            <antcall target="test2">
            <param name="fileName"  value="@{f}" />
            </antcall>
        </sequential>
        </for>  
</target>

I get the files name as E:/ant/test/1.txt ... I wanna just get 1.txt how to do?


Solution

  • You can use <basename/> task to get file name. More info can be found here.