Sort folder's contents by date

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
owend
Posts: 2
Joined: 07 Oct 2017, 04:29

Sort folder's contents by date

07 Oct 2017, 04:40

Hi there,

I have been writing an AHK script to open a number of explorer windows to different folders and arrange them on my screen using WinMove.

I need some of them to be arranged by date - can this be done in an ahk command? To save me going through each one, scrolling across to date modified and clicking (my windows are about 200x200 px), which usually takes 20 seconds. I need these folders sorted as soon ass possible after I open them.

Any and all suggestions welcome, but I am only a beginner with ahk!

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

Re: Sort folder's contents by date

07 Oct 2017, 06:34

Is your AHK script scrolling across to date modified and clicking in each window, or are you doing it manually? Seems like it should be a lot faster than 20 seconds (and a lot easier) if the script did it.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Sort folder's contents by date

07 Oct 2017, 07:57

I don't think that AutoHotkey has any built-in functionality for this, which is I worked on these functions:
Explorer column interaction (get/set: which appear, width, ascending/descending order) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=33129

Here is an example which sorts by the Date column:

Code: Select all

q:: ;sort columns by date modified
WinGet, hWnd, ID, A
oWin := JEE_ExpWinGetObj(hWnd)
JEE_ExpGetInterfaces(oWin, isp, isb, isv, ifv2, icm)
;MsgBox, % JEE_IFV2GetSortColumns(ifv2)
;1: ascending, -1: descending
;vList := "System.ItemNameDisplay 1" ;Name
vList := "System.ItemDate 1" ;Date
;vList := "System.ItemTypeText 1" ;Type
;vList := "System.Size 1" ;Size
;vList := "System.Media.Duration 1" ;Length
;vList := "System.DateModified 1" ;Date modified
JEE_IFV2SetSortColumns(ifv2, vList)
isp := isb := isv := ifv2 := icm := ""
return
Note: you would also need to copy and paste some (or all) of the functions from that link into your script, as well as the example code above. Or keep the functions in a separate script, see #Include.
#Include
https://autohotkey.com/docs/commands/_Include.htm

Some of this code might be useful for tiling windows. Note: it's a good idea to SetWinDelay to make it faster when moving windows.
Tiling notepad.exe - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36611
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
owend
Posts: 2
Joined: 07 Oct 2017, 04:29

Re: Sort folder's contents by date

07 Oct 2017, 10:36

Thanks jeeswg, I'll have a look through this and let you know if it works! Looks quite complicated...But I'll have a go :)

(@boiler, I meant it takes 20 seconds to click through them all! I hadn't found a way for AHK to do it!)
User avatar
boiler
Posts: 17194
Joined: 21 Dec 2014, 02:44

Re: Sort folder's contents by date

07 Oct 2017, 11:31

You can have AHK simulate your scrolls and clicks. That's what it's good at doing.
joefiesta
Posts: 498
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Sort folder's contents by date

10 Dec 2021, 10:26

It seems your code only sorts the Date Modified field ASCENDING.

You include the commented out line: ;1: ascending, -1: descending

The only line I see to modify from "1" to "-1" is: vList := "System.ItemDate 1" ;Date. But making that modification does not cause the script to sort DESCENDING. Am I missing something?

I run Windows 7 Pro, build 7601. My Explorer is version ??? (is there such a thing?)

Joe P.
just me
Posts: 9527
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Sort folder's contents by date

11 Dec 2021, 05:19

ShObjidl.h:

Code: Select all

/* [v1_enum] */ 
enum tagSORTDIRECTION
    {
        SORT_DESCENDING	= -1,
        SORT_ASCENDING	= 1
    } ;
:arrow: System.ItemDate

If "System.ItemDate 1" is working correctly for you, "System.ItemDate -1" should also work.

Otherwise you might try System.DateAccessed, System.DateCreated, or System.DateModified (see https://docs.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetpropertydescriptionbyname).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 75 guests