Operating on a filelist alphabetically by filename and not path? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Operating on a filelist alphabetically by filename and not path?

Post by chinagreenelvis » 20 Jan 2022, 09:52

I have files split into two directories like so:

Code: Select all

maindir\filename.ext
maindir\filename_c.ext
maindir\subdir\filename_a.ext
maindir\subdir\filename_q.ext
I need to operate on them in alphabetical order according to filename; not path. So:

Code: Select all

maindir\filename.ext
maindir\subdir\filename_a.ext
maindir\filename_c.ext
maindir\subdir\filename_q.ext
Is there any good way to do this without using arrays/attributes and parsing/sorting a list?

User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: Operating on a filelist alphabetically by filename and not path?

Post by boiler » 20 Jan 2022, 10:00

Would the maindir and subdir be known in advance by the script? Or perhaps supplied by the user of the script? Will those be the only files in those directories with those base names (the “filename” part), or would you somehow supply the base file name?

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Operating on a filelist alphabetically by filename and not path?

Post by just me » 20 Jan 2022, 12:18

Sort-> Options
\: Sorts items based on the substring that follows the last backslash in each. If an item has no backslash, the entire item is used as the substring. This option is useful for sorting bare filenames (i.e. excluding their paths), such as the example below, in which the AAA.txt line is sorted above the BBB.txt line because their directories are ignored for the purpose of the sort:

chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: Operating on a filelist alphabetically by filename and not path?  Topic is solved

Post by chinagreenelvis » 20 Jan 2022, 17:24

just me wrote:
20 Jan 2022, 12:18
Sort-> Options
\: Sorts items based on the substring that follows the last backslash in each. If an item has no backslash, the entire item is used as the substring. This option is useful for sorting bare filenames (i.e. excluding their paths), such as the example below, in which the AAA.txt line is sorted above the BBB.txt line because their directories are ignored for the purpose of the sort:
I must have missed this when looking at the sort entry before. This is exactly what I needed, thanks very much.

Post Reply

Return to “Ask for Help (v1)”