Thanks for the function and the update.
The script wasn't working correctly for the Windows 11 Version 10.0.22621+ tabbed explorer so I added an extra window title check.
Also now if you run
GetExplorerPath(0, false) it will only match the active window.
**Currently it doesn't work correctly if you have 2 opened tabs with the same title (such as C:\Folder1 and D:\Folder1.)
Code: Select all
GetExplorerPath(hwnd = 0, findWindow = true) {
if (hwnd == 0) {
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (findWindow && explorerHwnd == 0) {
explorerHwnd := WinExist("ahk_class CabinetWClass")
}
} else {
explorerHwnd := WinExist("ahk_class CabinetWClass ahk_id " . hwnd)
}
WinGetTitle, myTitle, ahk_id %explorerHwnd%
if (explorerHwnd) {
for window in ComObjCreate("Shell.Application").Windows {
try {
if (window && window.hwnd && window.hwnd == explorerHwnd && window.LocationName && window.LocationName == myTitle) {
return window.Document.Folder.Self.Path
}
}
}
}
return false
}
On my
ExploreEverything script I have decided to mainly use these three lines below and only use GetExplorerPath() for special folders like Pictures/Documents/Movies etc.
Code: Select all
ControlGet, crumbHWND, Hwnd,, Breadcrumb Parent1, A
ControlGetText, RunPath, ToolbarWindow321, ahk_id %crumbHWND%
RunPath := StrSplit(RunPath, ": ")[2]