Search code examples
loopsnant

NAnt foreach loop folders recursive


Does anybody know how I could create a recursive loop with NAnt? I need to loop through all of my folders and upload the files to our webserver. I am using this NAnt ftp task (http://www.spinthemoose.com/~ftptask), however it doesn't seem to upload the entire directory. It uploads only the mentioned files in my put element.

Thanks,


Solution

  • Foreach task. You can find examples looping through folders.

    Full example:

    <foreach item="Folder" property="foldername">
        <in>
            <items>
                <include name="YOUR_FOLDER\**" />
            </items>
        </in>
        <do>
            <foreach item="File" property="filename" in="${foldername}">
            <do>
                <echo message="${filename}" />
            </do>
            </foreach>              
        </do>
    </foreach>
    

    If you do not need folders, you can achieve your needs even with less code:

    <foreach item="File" property="filename">
        <in>
            <items>
                <include name="YOUR_FOLDER\**" />
            </items>
        </in>
        <do>
            <echo message="${filename}" />
        </do>
    </foreach>