Sort list of file paths in folder\subfolders order Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Sort list of file paths in folder\subfolders order

25 Dec 2019, 08:42

Is there a way to sort such a list

list =
(
c:\folder a\wfbt.txt
c:\folder c\blah.txt
c:\folder b\terp.txt
c:\folder b\subfolder c\phbt.txt
c:\folder a\subfolder a\hfbt.txt
)

in folder\subfolders order (alphabetically in each directory)?

That is, the result should be

c:\folder a\wfbt.txt
c:\folder a\subfolder a\hfbt.txt
c:\folder b\terp.txt
c:\folder b\subfolder c\phbt.txt
c:\folder c\blah.txt
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Sort list of file paths in folder\subfolders order

25 Dec 2019, 16:00

Code: Select all

list =
(
c:\folder a\wfbt.txt
c:\folder c\blah.txt
c:\folder b\terp.txt
c:\folder b\subfolder c\phbt.txt
c:\folder a\subfolder a\hfbt.txt
)
Sort, List
MsgBox % list
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
flyingDman
Posts: 870
Joined: 29 Sep 2013, 19:01

Re: Sort list of file paths in folder\subfolders order

25 Dec 2019, 16:23

@GEV can you be more explicit? How would a file like C:\zbra.txt rank? based on your result example, it would go to the top as c:\folder a\wfbt.txt ranks above c:\folder a\subfolder a\hfbt.txt and c:\folder b\terp.txt above c:\folder b\subfolder c\phbt.txt
. A simple "sort" as shown by @Odlanir would put C:\zbra.txt at the bottom. Sort is by far the easiest solution. Sorting based on the way you seem to want it is way more complicated...
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: Sort list of file paths in folder\subfolders order

25 Dec 2019, 17:00

@Odlanir,
thanks for your answer.

@flyingDman,
I would like to sort the files in the order they appear in the exlorer tree (files in the root folder before those in the subbolders and in alphabetical order in each of them).
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Sort list of file paths in folder\subfolders order

25 Dec 2019, 17:39

Loks like you need logical sort:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

list =
(
c:\folder a\wfbt.txt
c:\folder c\blah.txt
c:\folder b\terp.txt
c:\folder b\subfolder c\phbt.txt
c:\folder a\subfolder a\hfbt.txt
)
list2:= list
;Sort, List
;SortNW(s1, s2)
;MsgBox % list


;https://www.autohotkey.com/boards/viewtopic.php?p=246364#p246364
;var := "aBc 3 2 1 11 Abc 12 24 texT 78 94 9 7 72 Letters 99 101 Text", var1 := var
AW := A_IsUnicode ? "W": "A"
Sort, list ;, CL N
Sort, list2, CL F SortN%AW%
MsgBox, %list%`n`n%list2%



;================================================================
SortNA(s1, s2)
;================================================================
{
; for ANSI AHK we must first convert input strings to Unicode, then perform comparison
s1a := StrGet(&s1, "UTF-8"), s2a := StrGet(&s2, "UTF-8")
VarSetCapacity(s1b, 2*StrPut(s1a, "UTF-16"), 0), VarSetCapacity(s2b, 2*StrPut(s2a, "UTF-16"), 0)
StrPut(s1a, &s1b, "UTF-16"), StrPut(s2a, &s2b, "UTF-16")
return DllCall("shlwapi\StrCmpLogicalW", "Ptr", &s1b, "Ptr", &s2b, "Int")
}
;================================================================
SortNW(s1, s2)
;================================================================
{
return DllCall("shlwapi\StrCmpLogicalW", "Str", s1, "Str", s2, "Int")
}
User avatar
lvalkov
Posts: 56
Joined: 08 Mar 2019, 16:39

Re: Sort list of file paths in folder\subfolders order  Topic is solved

26 Dec 2019, 04:15

Implemented in v2-a108.
Backporting to v1 would necessitate substituting the Map for another case-sensitive collection, such as a Scripting.Dictionary or a different homebrewed one.
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: Sort list of file paths in folder\subfolders order

29 Dec 2019, 08:11

Amazing! THANKS a million!!!

Return to “Ask For Help”

Who is online

Users browsing this forum: AlexIII, ananthuthilakan, Bing [Bot], JoeWinograd, mikeyww, Netocon, Tulevik, WOlfen and 61 guests