Loops over a set of items.
Can loop over files in directory, lines in a file, etc.
The property value is stored before the loop is done, and restored when the loop is finished.
The property is returned to its normal value once it is used. Read-only parameters cannot be overridden in this loop.
Parameters
Nested elements
Examples
Loops over the files in c:\
.
<foreach item="File" in="c:\" property="filename">
<echo message="${filename}" />
</foreach>
Loops over all files in the project directory.
<foreach item="File" property="filename">
<in>
<items>
<include name="**" />
</items>
</in>
<do>
<echo message="${filename}" />
</do>
</foreach>
Loops over the folders in c:\
.
<foreach item="Folder" in="c:\" property="foldername">
<echo message="${foldername}" />
</foreach>
Loops over all folders in the project directory.
<foreach item="Folder" property="foldername">
<in>
<items>
<include name="**" />
</items>
</in>
<do>
<echo message="${foldername}" />
</do>
</foreach>
Loops over a list.
<foreach item="String" in="1 2,3" delim=" ," property="count">
<echo message="${count}" />
</foreach>
Loops over lines in the file properties.csv
, where each line
is of the format name,value.
<foreach item="Line" in="properties.csv" delim="," property="x,y">
<echo message="Read pair ${x}=${y}" />
</foreach>
Requirements
- Assembly
- NAnt
.Core .dll - Namespace
-
NAnt
.Core .Tasks