tags:

views:

972

answers:

1

Hi,

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,

+5  A: 

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>
Mike Chaliy
I already checked that, but there is no example to do it recursively.
vikasde
Example iv.Loops over all folders in the project directory. This is something you need.
Mike Chaliy
That seems to work with the default folder from NAnt, however if I change it to: <foreach item="Folder" property="foldername" in="...." > then it doesn't show me the recursive folders. Any ideas?
vikasde
Have you add "**" at the end of the path? This is key.
Mike Chaliy
No, I did not. Sorry this is my first day using NAnt. Your example works now. What does ** do?
vikasde
** - Folders recursivelly :). Wait a minute I will update example with new version.
Mike Chaliy
Sweet. Thanks a lot. Though it should be filename not filername (without the "r").
vikasde
No, it better to be filename, but filername is ok too.
Mike Chaliy
Just a quick followup question: How do I make it ignore my _svn folders?
vikasde
Take a look on exclude element.http://nant.sourceforge.net/release/latest/help/types/fileset.html
Mike Chaliy
Thanks Mike. I already did and it says that the _SVN folder is excluded automatically. Though it isnt'. I also tried to add the exlcude element, but that did not help either :(
vikasde
I got it working:<exclude name="**_svn**" />
vikasde