Sorting Batch File Results
You can use the dir command to sort your folders and echo them ...
for /f "delims=" %%a in ( 'dir /b /ad /oN') do echo %%a >> output.txt
And if you only want directory echo
dir / b / ad / oN -> output.txt
will be sufficient...
On the command line help for
and help dir
you can use ...
source to share
Just use the command sort
.
for /D %%A IN (*) DO echo %%A>> output.txt
sort output.txt > sorted_output.txt
you can find out more about this command by calling sort /?
or here .
As you can read with the command, you can use /O
to redirect the output to a file instead of stdout. And with that, you can avoid the need for two files:
for /D %%A IN (*) DO echo %%A>> output.txt
sort output.txt /O output.txt
EDIT: A good one-liner might be:
(for /D %%A IN (*) DO echo %%A) | sort > output.txt
It is also much faster as it writes the output once at the end.
source to share