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
Sort list of file paths in folder\subfolders order Topic is solved
Re: Sort list of file paths in folder\subfolders order
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
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Sort list of file paths in folder\subfolders order
@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...
. 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...
14.3 & 1.3.7
Re: Sort list of file paths in folder\subfolders order
@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).
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).
Re: Sort list of file paths in folder\subfolders order
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")
}
Re: Sort list of file paths in folder\subfolders order Topic is solved
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.
Backporting to v1 would necessitate substituting the Map for another case-sensitive collection, such as a Scripting.Dictionary or a different homebrewed one.
Re: Sort list of file paths in folder\subfolders order
Amazing! THANKS a million!!!