Wednesday, 11 September 2013

Read files in directory in order of number in filename with batch?

Read files in directory in order of number in filename with batch?

I have a number of SQL scripts in a directory, prefixed with a number, e.g.

Currently, I'm able to loop through them with this script:
@ECHO OFF
FOR /r . %%F IN (*.sql) DO (
ECHO File:"%%F"
)
but because of the way that Windows reads files in a directory, files 10
and 11 are read before 2, etc.:

How can I loop through each file in the directory, in order of the prefix?

No comments:

Post a Comment