In DOS batch file I can write following loop to iterate files in a directory in alphabetical ascending order:
for %f in (*) do (echo %f)
How do I do the same but iterate files in reverse order (alphabetical descending) ?
From the command line:
for /f "tokens=*" %f in ('dir /b /o-n') do (echo %f)
In a bat file:
for /f "tokens=*" %%f in ('dir /b /o-n') do (echo %%f)
/B Uses bare format (no heading information or summary).
/O List by files in sorted order.
sortorder N By name (alphabetic)
- Prefix to reverse order
Type "dir /?" in CMD for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With