Get current explorer window path
Posted: 17 Nov 2019, 05:51
I've been trying to find a good script to cleanly and reliably get the current path of an explorer window without tricks like reading it from the address bar or knowing the user profile name and so on. Having finally found the right interfaces and properties, I thought I'd share it for others:
If the string it returns starts with :: then it's a special folder of some sort, and doesn't really have a path as such.
Code: Select all
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}