Any chance for a v2 version? the comobjquery and numget stuff is a little beyond my knowledge scope and I'm hitting a brick wall with itntepa wrote: ↑15 Feb 2023, 02:54This function can get the path in Windows 11 tabbed explorer:
Code: Select all
GetActiveExplorerPath() { hwnd := WinActive("ahk_class CabinetWClass") activeTab := 0 try ControlGet, activeTab, Hwnd,, % "ShellTabWindowClass1", % "ahk_id" hwnd for w in ComObjCreate("Shell.Application").Windows { if (w.hwnd != hwnd) continue if activeTab { static IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}" shellBrowser := ComObjQuery(w, IID_IShellBrowser, IID_IShellBrowser) DllCall(NumGet(numGet(shellBrowser+0)+3*A_PtrSize), "Ptr", shellBrowser, "UInt*", thisTab) if (thisTab != activeTab) continue ObjRelease(shellBrowser) } return w.Document.Folder.Self.Path } }
Get current explorer window path
Re: Get current explorer window path
Re: Get current explorer window path
The v1 script was actually based on a v2 script: viewtopic.php?f=83&t=109907
Re: Get current explorer window path
Anybody know whether a similar approach is available to get the path of the directory currently displayed by standard File Open or Save dialogs? Despite the similar appearance, they're not shell window objects, but are they some other sort of object with readable properties?
Thanks.
JB
Thanks.
JB
Re: Get current explorer window path
Should this also work in Win10?ntepa wrote: ↑15 Feb 2023, 02:54This function can get the path in Windows 11 tabbed explorer:
Code: Select all
GetActiveExplorerPath() { hwnd := WinActive("ahk_class CabinetWClass") activeTab := 0 try ControlGet, activeTab, Hwnd,, % "ShellTabWindowClass1", % "ahk_id" hwnd for w in ComObjCreate("Shell.Application").Windows { if (w.hwnd != hwnd) continue if activeTab { static IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}" shellBrowser := ComObjQuery(w, IID_IShellBrowser, IID_IShellBrowser) DllCall(NumGet(numGet(shellBrowser+0)+3*A_PtrSize), "Ptr", shellBrowser, "UInt*", thisTab) if (thisTab != activeTab) continue ObjRelease(shellBrowser) } return w.Document.Folder.Self.Path } }
Re: Get current explorer window path
Yes, it does work in Win10 for me.
JB
JB
Re: Get current explorer window path
it will freeze if any explorer window is frozen!!!
will freeze accessing ComObjCreate("Shell.Application").Windows
will freeze using ahk v1.
will freeze accessing ComObjCreate("Shell.Application").Windows
will freeze using ahk v1.
Re: Get current explorer window path
another olution, get path from address bar ( need acc library)
Code: Select all
GetActiveExplorerPath()
{
Try
{
WinGetPos,x,y,w,h
acc := Acc_ObjectFromPoint(null, x+w-300, y+90)
f := acc && StartsWith(t := acc.accName(0), "Address:")
if(!f) {
Loop, 35 {
acc := Acc_ObjectFromPoint(null, x+w-35*A_Index, y+90)
if(acc && StartsWith(t := acc.accName(0), "Address:")) {
f := 1
break
}
}
}
if(f)
return SubStr(t, 9)
; explorerHwnd := WinActive...
}
}
Re: Get current explorer window path
And yet another option...
viewtopic.php?f=76&t=51793#p228408
viewtopic.php?f=76&t=51793#p228408
Code: Select all
#IfWinActive, ahk_class CabinetWClass
q:: ;Explorer window - copy focused item path (if item selected) else folder path
#IfWinActive, ahk_class ExploreWClass
q:: ;Explorer window - copy focused item path (if item selected) else folder path
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
if !(vCtlClassNN = "DirectUIHWND3")
{
SendInput, ^c
return
}
vPath := ""
for oWin in ComObjCreate("Shell.Application").Windows
if (oWin.HWND = hWnd)
{
vPath := oWin.Document.FocusedItem.Path
if (vPath = "")
vPath := oWin.Document.Folder.Self.Path
else
{
vIsSelected := 0
for oItem in oWin.Document.SelectedItems
if (vPath = oItem.Path)
{
vIsSelected := 1
break
}
if !vIsSelected
vPath := oWin.Document.Folder.Self.Path
}
break
}
oWin := oItem := ""
Clipboard := vPath
MsgBox, % vPath
return
#IfWinActive
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 171 guests