Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAnt foreach loop folders recursive

Tags:

loops

nant

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,

like image 315
vikasde Avatar asked Dec 07 '22 06:12

vikasde


2 Answers

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>
like image 167
Mike Chaliy Avatar answered Dec 25 '22 07:12

Mike Chaliy


I believe this should give you the recursive list of folders

<?xml version="1.0"?>

<target name="task.recursive">
    <foreach item="Folder" in="${folder.current}" property="folder">
        <echo message="${folder}" />
        <property name="folder.current" value="${folder}" />
        <call target="task.recursive" />
    </foreach>
</target>

<target name="task.run">
    <echo message="${project.folder.root}" level="Info" />
    <property name="folder.current" value="${project.folder.root}" />
    <call target="task.recursive" />
</target>

like image 43
user2471094 Avatar answered Dec 25 '22 09:12

user2471094