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.
source share