I want to use NAnt foreach to iterate files in a folder, how to force alphabetical iteration?

I have a NAnt send task to pack my current .sql scripts into an assembly, and then name the assembly with incremental int {######} and copy it to the assembly folder.

I have another NAnt task that runs these build scripts.

They should be executed in order, but in my last attempt they were not. Can I "make" NAnt work in alphabetical order?

+4
source share
3 answers

FAIL:

<fileset basedir="source\tsql\builds\" id="buildfiles"> <include name="*.sql.template.sql" /> <exclude name="*.sql" /> <exclude name="*asSentTo*" /> </fileset> <foreach item="File" property"filename"> <in refid="buildfiles"> <echo message="${filename}" /> </in> </foreach> 

PASS:

 <foreach item="File" property="filename" in="source\tsql\builds"> <do> <if test="${string::ends-with(filename,'.sql.template.sql')}"> <echo message="${filename}" /> </if> </do> </foreach> 
+4
source

To satisfy my curiosity, I tried to reproduce the problem with this script:

 <?xml version="1.0"?> <project name="foreach.test" default="foreach.alpha"> <target name="foreach.alpha"> <foreach item="File" in="C:\foo" property="filename"> <do> <echo message="${filename}" /> </do> </foreach> </target> </project> 

File names are printed in alphabetical order. Therefore, the traditional use of foreach already seems to be the solution to the problem.

+1
source

Here's how you do it with a set of files

 <fileset id="mySet"> <include name="*.sql" /> </fileset> <copy> <fileset refid="mySet" /> </copy> <foreach item="File" property="filename"> <in> <items refid="mySet" /> </in> <do> <echo message="Copied files: ${filename} to directory: ${Folder}." /> </do> </foreach> 
+1
source

Source: https://habr.com/ru/post/1302262/


All Articles