sorting files by folder path Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
haomingchen1998
Posts: 176
Joined: 20 Feb 2023, 16:37

sorting files by folder path

29 Oct 2023, 20:18

viewtopic.php?t=95352

I got the code below from the above link, and I'm just wondering if I can make it to apply this sorting for 2 specific folders upon launching the script instead of needing a hotkey to trigger? I'm thinking of using a winactive title, but I still prefer to specify a path for reliability. Are there better ideas that I'm not thinking of? Thanks!

Code: Select all

#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe
    F1::
    For oWin in ComObjCreate("Shell.Application").Windows {
    If WinActive() != oWin.HWND
    Continue
    oWin.Document.GroupBy     := "System.ItemTypeText"
    oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;"
    Return
    }
    Return
#IfWinActive
User avatar
mikeyww
Posts: 27269
Joined: 09 Sep 2014, 18:38

Re: sorting files by folder path  Topic is solved

29 Oct 2023, 21:02

Ideas are below.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
specialPath := "C:\Windows|C:\Windows\System32"
regEx       := "(" StrReplace(specialPath, "\", "\\") ")"
Loop {
 WinWaitActive ahk_class CabinetWClass
 hWnd := WinActive("A")
 SetTimer Check, 100
 SoundBeep 1500
 WinWaitNotActive
 SetTimer Check, Off
 SoundBeep 1000
}

Check:
last := current, current := explorerGetPath()
If (current != last && current ~= regex)
 For oWin in ComObjCreate("Shell.Application").Windows
  If (hWnd = oWin.Hwnd) {
   oWin.Document.GroupBy     := "System.ItemTypeText"           ; Group by item type
   oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ; Reverse sort by item name
   SoundBeep 2500
  }
Return

explorerGetPath(hwnd := 0){ ; https://www.autohotkey.com/boards/viewtopic.php?p=387113#p387113
 If hWnd
  explorerHwnd := WinExist( "ahk_class CabinetWClass ahk_id " . hwnd )
 Else If !explorerHwnd := WinActive("ahk_class CabinetWClass")
  explorerHwnd := WinExist("ahk_class CabinetWClass")
 If explorerHwnd
  For window in ComObjCreate("Shell.Application").Windows
   Try If (window && window.hwnd && window.hwnd==explorerHwnd)
    Return window.Document.Folder.Self.Path
 Return False
}
haomingchen1998
Posts: 176
Joined: 20 Feb 2023, 16:37

Re: sorting files by folder path

30 Oct 2023, 18:29

mikeyww wrote:
29 Oct 2023, 21:02
Ideas are below.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
specialPath := "C:\Windows|C:\Windows\System32"
regEx       := "(" StrReplace(specialPath, "\", "\\") ")"
Loop {
 WinWaitActive ahk_class CabinetWClass
 hWnd := WinActive("A")
 SetTimer Check, 100
 SoundBeep 1500
 WinWaitNotActive
 SetTimer Check, Off
 SoundBeep 1000
}

Check:
last := current, current := explorerGetPath()
If (current != last && current ~= regex)
 For oWin in ComObjCreate("Shell.Application").Windows
  If (hWnd = oWin.Hwnd) {
   oWin.Document.GroupBy     := "System.ItemTypeText"           ; Group by item type
   oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ; Reverse sort by item name
   SoundBeep 2500
  }
Return

explorerGetPath(hwnd := 0){ ; https://www.autohotkey.com/boards/viewtopic.php?p=387113#p387113
 If hWnd
  explorerHwnd := WinExist( "ahk_class CabinetWClass ahk_id " . hwnd )
 Else If !explorerHwnd := WinActive("ahk_class CabinetWClass")
  explorerHwnd := WinExist("ahk_class CabinetWClass")
 If explorerHwnd
  For window in ComObjCreate("Shell.Application").Windows
   Try If (window && window.hwnd && window.hwnd==explorerHwnd)
    Return window.Document.Folder.Self.Path
 Return False
}
This is SO COOL, thank you!!!
haomingchen1998
Posts: 176
Joined: 20 Feb 2023, 16:37

Re: sorting files by folder path

07 Jan 2024, 11:46

mikeyww wrote:
29 Oct 2023, 21:02
Ideas are below.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
specialPath := "C:\Windows|C:\Windows\System32"
regEx       := "(" StrReplace(specialPath, "\", "\\") ")"
Loop {
 WinWaitActive ahk_class CabinetWClass
 hWnd := WinActive("A")
 SetTimer Check, 100
 SoundBeep 1500
 WinWaitNotActive
 SetTimer Check, Off
 SoundBeep 1000
}

Check:
last := current, current := explorerGetPath()
If (current != last && current ~= regex)
 For oWin in ComObjCreate("Shell.Application").Windows
  If (hWnd = oWin.Hwnd) {
   oWin.Document.GroupBy     := "System.ItemTypeText"           ; Group by item type
   oWin.Document.SortColumns := "prop:-System.ItemNameDisplay;" ; Reverse sort by item name
   SoundBeep 2500
  }
Return

explorerGetPath(hwnd := 0){ ; https://www.autohotkey.com/boards/viewtopic.php?p=387113#p387113
 If hWnd
  explorerHwnd := WinExist( "ahk_class CabinetWClass ahk_id " . hwnd )
 Else If !explorerHwnd := WinActive("ahk_class CabinetWClass")
  explorerHwnd := WinExist("ahk_class CabinetWClass")
 If explorerHwnd
  For window in ComObjCreate("Shell.Application").Windows
   Try If (window && window.hwnd && window.hwnd==explorerHwnd)
    Return window.Document.Folder.Self.Path
 Return False
}
I know I can use the below code to group by type, but can I set groupby to none after I'm done? I wasn't able to find anything that either reset it, or group by none. Thanks!

Code: Select all

oWin.Document.GroupBy     := "System.ItemTypeText"  
User avatar
mikeyww
Posts: 27269
Joined: 09 Sep 2014, 18:38

Re: sorting files by folder path

07 Jan 2024, 12:31

Windows File Explorer Shell GroupBy Values for COM

System.ItemNameDisplay
System.DateModified
System.ItemTypeText
System.Size
System.DateCreated
System.Author
System.Keywords
System.Title
System.Null
haomingchen1998
Posts: 176
Joined: 20 Feb 2023, 16:37

Re: sorting files by folder path

07 Jan 2024, 13:53

mikeyww wrote:
07 Jan 2024, 12:31
Windows File Explorer Shell GroupBy Values for COM

System.ItemNameDisplay
System.DateModified
System.ItemTypeText
System.Size
System.DateCreated
System.Author
System.Keywords
System.Title
System.Null
Really appreciate it, worked as expected!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RickC and 87 guests