Autohotkey and Windows 10: How to get current explorer path

Deadly 提交于 2019-12-23 05:11:45

问题


I use autohotkey version: 1.0.48.05 (because I stick with activeaid). The script to read the current path is as follows (and worked until 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")

How I suspect that while switching to Win10 it seems that I also switched the language. If I MsgBox out the %FullPath% before cleaning with WinGetText, FullPath, A MsgBox %FullPath% I see amongst other strings (obvoíously separated by CR): Adresse: V:\Vertrieb\Prospects\MyFile

so how do I need to adjust the regexp to extract that very string!

Best regards Hannes


回答1:


Try:

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
}



回答2:


#If WinActive("ahk_class CabinetWClass") ; explorer

    F1::
    WinGetTitle, ActiveTitle, A
    If InStr(ActiveTitle, "\")  ; If the full path is displayed in the title bar (Folder Options)
        Fullpath := ActiveTitle
    else
    If InStr(ActiveTitle, ":") ; If the title displayed is something like "DriveName (C:)"
    {
        Fullpath := SubStr(ActiveTitle, -2)
        Fullpath := SubStr(Fullpath, 1, -1)
    }
    else    ; If the full path is NOT displayed in the title bar 
    ; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
    for window in ComObjCreate("Shell.Application").Windows
    {
        try Fullpath := window.Document.Folder.Self.Path
        SplitPath, Fullpath, title
        If (title = ActiveTitle)
            break
    }
    MsgBox, %Fullpath%
    return 

#If



回答3:


It takes me so much time to find the best solution (for me). Maybe it will work for you as well.

ControlClick, ToolbarWindow323, A
ControlGetText, path, Edit1, A
Msgbox, %path%


来源:https://stackoverflow.com/questions/39253268/autohotkey-and-windows-10-how-to-get-current-explorer-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!