Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping files in directory in reverse order

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) ?

like image 275
gerrytan Avatar asked Oct 21 '25 06:10

gerrytan


1 Answers

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
like image 89
RGuggisberg Avatar answered Oct 23 '25 20:10

RGuggisberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!