Autohotkey 和 Windows 10:如何获取当前资源管理器路径

use*_*338 1 autohotkey regexp-replace

我使用 autohotkey 版本:1.0.48.05(因为我坚​​持使用 activeaid)。读取当前路径的脚本如下(一直工作到 Win 7)。

; Get full path from open Explorer window
WinGetText, FullPath, A

; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")
Run Code Online (Sandbox Code Playgroud)

我怀疑在切换到 Win10 时,我似乎也切换了语言。如果我在使用 WinGetText、FullPath、A MsgBox %FullPath% 清理之前将 MsgBox 排除在 %FullPath% 中,我会在其他字符串中看到(显然由 CR 分隔):地址:V:\Vertrieb\Prospects\MyFile

那么我需要如何调整正则表达式来提取那个字符串!

最好的问候汉内斯

use*_*297 7

#If WinActive("ahk_class CabinetWClass") ; explorer

    F1:: MsgBox, % GetActiveExplorerPath()

    ; or
    F2:: 
        ActiveExplorerPath := GetActiveExplorerPath()
        MsgBox, % ActiveExplorerPath
    return

#If

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925

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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


err*_*ven 5

尝试:

f1::MsgBox % Explorer_GetSelection()

Explorer_GetSelection(hwnd="") {
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
    if  (process = "explorer.exe") 
        if (class ~= "(Cabinet|Explore)WClass") {
            for window in ComObjCreate("Shell.Application").Windows
                if  (window.hwnd==hwnd)
                    path := window.Document.FocusedItem.path

            SplitPath, path,,dir
        }
        return dir
}
Run Code Online (Sandbox Code Playgroud)