We have deployment cmd file in which we use
dir /s /od /b Current\*.sql
it was working fine till 99.sql but when we introduce 100.sql the 100.sql runs before 99.sql how to correct the sort order ? 100.sql is created after 99.sql so /od should list 99.sql before 100.sql.
So help me how to get right order.
Asked
Active
Viewed 52 times
0

Shan
- 578
- 5
- 18
-
2Alot easier to copy and paste the text from the console window then posting a screen shot. – Squashman Feb 22 '18 at 15:10
2 Answers
1
The absolute easiest way is to zero-pad all the numbers, i.e. 61
becomes 0061
, but this'll require doing it to the old files as well.
Failing that, you can sort the files naturally; there seems to be an answer for that here. Naturally Sort Files in Batch

AKX
- 152,115
- 15
- 115
- 172
0
Try
for /f "delims=" %%a in ('dir /b /od /ad "current*"') do if exist "current\%%a\*.sql" dir /s /b /od "current\%%a\*.sql"
This should first scan current
for directorynames (/ad
) in date-order (/od
) then look for files matching "current*namefound**.sql" and list if any exist.

Magoo
- 77,302
- 8
- 62
- 84