rsenn / grub4dos-chenall

Automatically exported from code.google.com/p/grub4dos-chenall
0 stars 0 forks source link

Request: ls --sort /folder for sorted directory contents #147

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Would be nice to get an alphabetically sorted list of files

At the moment the results of  ls /  depends on the order that files were 
written in. So the same folder on two different drives with same contents is 
listed differently by grub4dos!

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by Steve6375 on 5 Jul 2013 at 10:09

GoogleCodeExporter commented 9 years ago
P.S. also --rsort for reverse sort?  ;-)

Original comment by Steve6375 on 5 Jul 2013 at 10:12

GoogleCodeExporter commented 9 years ago
This is best achieved using external commands.
eg. dir.g4b or dir.g4e

Original comment by chenall.cn on 10 Jul 2013 at 1:30

GoogleCodeExporter commented 9 years ago
I use an external command at the moment but it is very slow.
I was hoping that an internal sort would be much faster...

:: get dir listing and sort entries alphabetically
set sortlist=(md)0x25000+0x50
echo -e -n \x00\x00 > %sortlist%
ls | call :sort 
cat %sortlist% | call :copyfiles 
set sortlist=

:: ------------ SORT LIST -----
:sort
set /a count=0 > nul
echo -e \x00\x00 > %memlist%
if "%1"=="" goto :eof
set mem=0x23450
:loop
if "%1"=="" goto :startSort
if "#%~x1#"=="##" shift && goto :loop
if "#%~x1#"=="#.txt#" shift && goto :loop
if "#%~x1#"=="#.mnu#" shift && goto :loop
set s=%1
set /A mem1=%mem%+%count% > nul
echo %1 > (md)%mem1%+1
set /A count=%count%+1 > nul
shift
goto loop

:startSort
::echo STARTSORT count=%count% && pause
if "%count%"=="0" exit
if "%count%"=="0x1" echo -n %s% > %sortlist%  &&  goto :eof
set /a total=%count%-1 > nul
:: Following code runs many times so make efficient!

:RestartSort
set count=0 > nul

:sortLoop
set /a next=%count%+1 > nul
call :swap %count% %next%
set /a count=%count%+1 > nul
if "%swapped%"=="1" goto :RestartSort
if "%count%"=="%total%" goto :output || goto :sortLoop

:swap
set /A mem1=%mem%+%1 > nul && set /A mem2=%mem%+%2 > nul
cat (md)%mem1%+1 | set var1= && cat (md)%mem2%+1 | set var2=
if %var1%<=%var2% set swapped= && goto :eof
echo %var1% > (md)%mem2%+1 && echo %var2% > (md)%mem1%+1
set swapped=1 && goto :eof

:output
set count=0
set /a total=%total%+1 > nul
:llp
if %count%>=%total% goto :tidyup
set /A mem1=%mem%+%count% > nul
cat (md)%mem1%+1 | set f=
echo -n %f% >> %sortlist%
echo -n -e \x20 >> %sortlist%
::| set %sortlist%=%sortlist% 
set /a count=%count%+1 > nul
goto :llp

:tidyup
set mem=
set mem1=
set mem2=
set var1=
set var2=
set count=
set total=
set swapped=
::cat %sortlist% && pause

Original comment by Steve6375 on 10 Jul 2013 at 5:17