Code: Select all
List := "Folder 8" . "`nFolder 9" . "`nFolder 10" . "`nFolder 11"
Sort , List
MsgBox , % List
In Windows file explorer, sorting gives the desired:Folder 10
Folder 11
Folder 8
Folder 9
But when sorting files, Windows produces the same result as AHK.Folder 8
Folder 9
Folder 10
Folder 11
It seems possible to workaround by specifying our own custom sort rules by using F parameter. However that seems to require implementing the sort from scratch on a per-character basis, which kind of defeats the purpose of using Sort, and there would probably be edge cases where my implementation would fail. Is there an easier way?
I think the rule I want is that when it compares chars between items it should treat " " or "" as having higher alphabetical order than any number?
https://www.autohotkey.com/docs/commands/Sort.htm wrote:Sort , List , F
"F MyFunction [v1.0.47+]: Uses custom sorting according to the criteria in MyFunction (though sorting takes much longer). Specify the letter "F" followed by optional spaces/tabs followed by the name of a function to be used for comparing any two items in the list. The function must accept two or three parameters. When the function deems the first parameter to be greater than the second, it should return a positive integer; when it deems the two parameters to be equal, it should return 0, "", or nothing; otherwise, it should return a negative integer. If a decimal point is present in the returned value, that part is ignored (i.e. 0.8 is the same as 0). If present, the third parameter receives the offset (in characters) of the second item from the first as seen in the original/unsorted list (see examples). Finally, the function uses the same global settings (e.g. StringCaseSense) as the Sort command that called it."