Jump to content

File list sort with default Windows enumeration


Recommended Posts

Hi guys, I wonder if there is a way to sort the filelist in an array from _FileListToArray () when files have the regular Windows enumeration example: File1 (1), File2 (2), File3 (3), etc. I'm posting two sample graphics so you can see what I mean I would like to get my list like in graphic 2 right now I'm getting my list like in graphic 1 which is the something I don't like. It's worth to say that I have no problem with a list when the files's names start with a number or is just a number thanks to the code found in this post. But, the problem is still present if I just get rid of the parenthesis that is () so in other words the problem happens when the enumeration is at the end of the names whether parenthesis are present or not.

2dce5ic.jpg    20pzp68.jpg

Edited by Mannyfresh15
Link to comment
Share on other sites

Test this script:

#include <DynArray.au3>
Global $a_Array[] = ['{2} Bla', '{1} Bla', '[2] Bla', '[1] Bla', '(1) Bla', '(10) Blub', "Test 8 Test", "Test 10 Test", "Test 9 Test", "Test 10 Test 9 Test", "Test 10 Test 10 Test", "Test 10 Test 8 Test", '(11) Ccc', '(12) Ddd', '(2) Haa', '(3) Hoo', '(4) Muh', '(5) Wuff', '(6) Brr', '(7) Klirr', '(8) Knarr', '(9) Uff', 'Hallo', 'Welt', 'AutoIt', 'Bla 10', 'Bla 9', '1 Bla', '10 Blub', '11 Ccc', '12 Ddd', '2 Haa', '3 Hoo', '4 Muh', '5 Wuff', '6 Brr', '7 Klirr', '8 Knarr', '9 Uff', ' Space']
_ArraySortFlexible($a_Array, MyCompare)
_ArrayDisplay($a_Array)
Func MyCompare(Const $A, Const $B)
    Local Static $h_DLL_Shlwapi = DllOpen("Shlwapi.dll")
    If IsString($A) Or IsString($B) Then
        Local $a_Ret = DllCall($h_DLL_Shlwapi, "int", "StrCmpLogicalW", "wstr", $A, "wstr", $B)
        If @error Then Return SetError(1, @error, 0)
        Return $a_Ret[0]
    EndIf
    ; normale Sortierung
    Return $A > $B ? 1 : $A < $B ? -1 : 0
EndFunc   ;==>MyCompare

It's the second script in https://autoit.de/index.php/Thread/84398-Sortierung-wie-im-Explorer-Tree-wie-gehts/?postID=675259#post675259 coded by @AspirinJunkie. The included DynArray.au3 is also from him.

 

Link to comment
Share on other sites

43 minutes ago, AutoBert said:

Test this script:

#include <DynArray.au3>
Global $a_Array[] = ['{2} Bla', '{1} Bla', '[2] Bla', '[1] Bla', '(1) Bla', '(10) Blub', "Test 8 Test", "Test 10 Test", "Test 9 Test", "Test 10 Test 9 Test", "Test 10 Test 10 Test", "Test 10 Test 8 Test", '(11) Ccc', '(12) Ddd', '(2) Haa', '(3) Hoo', '(4) Muh', '(5) Wuff', '(6) Brr', '(7) Klirr', '(8) Knarr', '(9) Uff', 'Hallo', 'Welt', 'AutoIt', 'Bla 10', 'Bla 9', '1 Bla', '10 Blub', '11 Ccc', '12 Ddd', '2 Haa', '3 Hoo', '4 Muh', '5 Wuff', '6 Brr', '7 Klirr', '8 Knarr', '9 Uff', ' Space']
_ArraySortFlexible($a_Array, MyCompare)
_ArrayDisplay($a_Array)
Func MyCompare(Const $A, Const $B)
    Local Static $h_DLL_Shlwapi = DllOpen("Shlwapi.dll")
    If IsString($A) Or IsString($B) Then
        Local $a_Ret = DllCall($h_DLL_Shlwapi, "int", "StrCmpLogicalW", "wstr", $A, "wstr", $B)
        If @error Then Return SetError(1, @error, 0)
        Return $a_Ret[0]
    EndIf
    ; normale Sortierung
    Return $A > $B ? 1 : $A < $B ? -1 : 0
EndFunc   ;==>MyCompare

It's the second script in https://autoit.de/index.php/Thread/84398-Sortierung-wie-im-Explorer-Tree-wie-gehts/?postID=675259#post675259 coded by @AspirinJunkie. The included DynArray.au3 is also from him.

 

@AutoBert

This solved my problem, thank you very much! I really really appreciated.

@mikell

thanks for your advice I'm looking at it and looks interesting

Edited by Mannyfresh15
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...