Get current explorer window path

Post your working scripts, libraries and tools for AHK v1.1 and older
Tomshi
Posts: 6
Joined: 06 Sep 2022, 20:58
Contact:

Re: Get current explorer window path

20 Dec 2023, 07:56

ntepa wrote:
15 Feb 2023, 02:54
This 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
    }
}
Any chance for a v2 version? :cry: the comobjquery and numget stuff is a little beyond my knowledge scope and I'm hitting a brick wall with it
ntepa
Posts: 429
Joined: 19 Oct 2022, 20:52

Re: Get current explorer window path

20 Dec 2023, 14:40

Tomshi wrote:
20 Dec 2023, 07:56
Any chance for a v2 version?
The v1 script was actually based on a v2 script: viewtopic.php?f=83&t=109907
JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: Get current explorer window path

15 Mar 2024, 07:42

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
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Get current explorer window path

15 Mar 2024, 10:21

ntepa wrote:
15 Feb 2023, 02:54
This 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
    }
}
Should this also work in Win10?
JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: Get current explorer window path

15 Mar 2024, 11:34

Yes, it does work in Win10 for me.

JB
Skrell
Posts: 302
Joined: 23 Jan 2014, 12:05

Re: Get current explorer window path

15 Mar 2024, 11:54

JBensimon wrote:
15 Mar 2024, 11:34
Yes, it does work in Win10 for me.

JB
TY!
KnIfER
Posts: 12
Joined: 27 Nov 2023, 06:10

Re: Get current explorer window path

19 Mar 2024, 12:09

it will freeze if any explorer window is frozen!!!

will freeze accessing ComObjCreate("Shell.Application").Windows

will freeze using ahk v1.
KnIfER
Posts: 12
Joined: 27 Nov 2023, 06:10

Re: Get current explorer window path

20 Mar 2024, 07:48

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...
	}
}
User avatar
V0RT3X
Posts: 236
Joined: 20 May 2023, 21:59
Contact:

Re: Get current explorer window path

20 Mar 2024, 09:37

And yet another option...
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: jamith and 202 guests