Running All of the Sql Files in a Directory

Just got asked a question by Scott Cowan :

Q: is there a way in nant to run a call for each .sql file in a dir ?

A: If you wanted to execute the scripts for a whole directory of sql files (and the order of the files running is not important), then you can take advantage of the NAnt task. Here is an example of a target that you could set up to run all of the sql files in a specific folder:

<foreach item="File" property="filename">
      <items basedir="${folder}">
         <include name="*.sql"/>     
      <property name="target" value="${filename}"/>
      <call target="exec.sql.template"/>

Notice that you would want to call this target from another target that sets the folder property to execute against:

 <property name="folder" value="sql"/>

<call target="exec.sql.folder"/>

Hope this helps.