Mannyfresh15

File list sort with default Windows enumeration

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

 

Share this post


Link to post
Share on other sites

Have a seach on Google using "autoit natural sort"  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Glad, i could help :)

Share this post


Link to post
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

  • Similar Content

    • TheDcoder
      By TheDcoder
      Hi, I have a 2D array with 2 columns, the 1st column contains a "version string" and the 2nd column contains a generic string. I want to sort it in the descending order so the latest version comes first.
      #include <Array.au3> Local $aVersionsAndReleases[4][2] = [["0.2.8.9", "Release #1"], ["0.2.9.10", "Release #3"], ["0.2.9.11", "Release #4"], ["0.2.8.10", "Release #2"]] _ArraySort($aVersionsAndReleases, 1) ConsoleWrite(_ArrayToString($aVersionsAndReleases, ' - ')) _ArrayDisplay($aVersionsAndReleases) Unfortunately, _ArraySort isn't working here . This is the output generated by the script:
      0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.9 - Release #1 0.2.8.10 - Release #2 The expected result should be:
      0.2.9.11 - Release #4 0.2.9.10 - Release #3 0.2.8.10 - Release #2 0.2.8.9 - Release #1 I am looking to develop an function which does this... but I don't know where to start . Can someone help me get started? Thanks in Advance!
      - TD.
    • PINTO1927
      By PINTO1927
      Hello guys,
      I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing.
      #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StructureConstants.au3> Opt('MustDeclareVars', 1) Global $search_LV, $B_DESCENDING GUICreate("ListView Sort by Column Click", 400, 300) $search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("line4|5|1A", $search_LV) GUICtrlCreateListViewItem("line5|4.50 |1B", $search_LV) GUICtrlCreateListViewItem("line10|4.0 |2C", $search_LV) GUICtrlCreateListViewItem("line3|23|01", $search_LV) GUICtrlCreateListViewItem("line2|0.34560 |09", $search_LV) GUICtrlCreateListViewItem("line1|1.0 |7A", $search_LV) GUICtrlCreateListViewItem("line1|0.1 |8C", $search_LV) GUICtrlCreateListViewItem("line1|97|5B", $search_LV) GUICtrlCreateListViewItem("line1|910|9B", $search_LV) GUICtrlCreateListViewItem("line1|99|11", $search_LV) GUICtrlCreateListViewItem("line1|990.99|06", $search_LV) _GUICtrlListView_SetColumnWidth($search_LV, 0, 75) _GUICtrlListView_SetColumnWidth($search_LV, 1, 75) _GUICtrlListView_SetColumnWidth($search_LV, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ _GUICtrlListView_RegisterSortCallBack($search_LV, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $search_LV ; Kick off the sort callback ;~ _GUICtrlListView_SortItems($search_LV, GUICtrlGetState($search_LV)) ;~ _GUICtrlListView_UnRegisterSortCallBack($search_LV) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $search_LV ;~ If Not IsHWnd($search_LV) Then $hWndListView = GUICtrlGetHandle($search_LV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom ;~ Case $search_LV Case GUICtrlGetHandle($search_LV) Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked ConsoleWrite("Header geklickt" & @CRLF) Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam) _GUICtrlListView_UnRegisterSortCallBack($search_LV) Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If $ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order?
      thank you very much
    • Peggy
      By Peggy
      I want to coding a excel sort,scheduling system.
      When I input orgin file,and choose times(example is 7 times(A -->G))
      system will output excel.
      (rule: 1 time include 1 Name ,but Food can't Repeat.
             secend's Food can't overlap with previous)
      How to codng of it ?!!!!
      Thank you veryvery much!!!!!!
      test.xlsx
    • Wolfiesaxah
      By Wolfiesaxah
      Hi guys, I am using an old version of Excel.au3 which I am not ready to update yet so please help me. The old Excel.au3 does not have any method for SORT. I attempted to create one since i need one but I am getting an error. Here's my sample code:
      $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,5),1,1) I thought this would work but I get the  
      : ==> The requested action with this object has failed.: $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,$BidDayColNumber),1,1) $oAppl.Activesheet.UsedRange.sort($oAppl.Activesheet.cells(1,$BidDayColNumber),1,1)^ ERROR Any ideas or alternatives on sorting a range without calling from Excel.au3?
    • Alexxander
      By Alexxander
      Hi 
      I'am trying to list files from folder sorted by name (same as the picture)

      i tried this code
      #include <File.au3> $arr = _FileListToArray("D:\2") _ArrayDisplay($arr) i am getting this result
       

      Any one could explain why it is putting 10-1 before 8-1 ?
      how can i make Autoit view file same as windows explorer ?