Windows 当路径包含散列时,“导航外壳程序”命令不起作用

Windows 当路径包含散列时,“导航外壳程序”命令不起作用,windows,shell,autohotkey,windows-shell,Windows,Shell,Autohotkey,Windows Shell,当路径包含#符号时,我在使用Navigate Shell命令时遇到问题 Alt-1效果很好。但是,使用Alt-2时,导航命令返回“file:///C:/delete#me/»未找到。“ 如果“#”(例如myPath:=“C:\delete#me”)后面没有“/”,则它可以工作。但这不是一个解决方案,因为目标路径可以在子文件夹中更深一些(例如“C:\delete\me\xyz”) 我试图将“#”编码为“%23”,但没有成功。在网上或MSDN上找不到任何与此相关的信息。有什么想法吗 [关键词:has

当路径包含#符号时,我在使用Navigate Shell命令时遇到问题

Alt-1效果很好。但是,使用Alt-2时,导航命令返回“file:///C:/delete#me/»未找到。“

如果“#”(例如myPath:=“C:\delete#me”)后面没有“/”,则它可以工作。但这不是一个解决方案,因为目标路径可以在子文件夹中更深一些(例如“C:\delete\me\xyz”)

我试图将“#”编码为“%23”,但没有成功。在网上或MSDN上找不到任何与此相关的信息。有什么想法吗


[关键词:haskmark、hashtag、数字符号或磅]

不幸的是,似乎没有解决方案。如果路径包含散列(如在C:\C\Projects中),则Shell.Application-Navigate命令将失败

使用AutoHotkey,解决方法将依赖于此线程中的测试确定的“第二最佳”方法:


如果您想打开一个新窗口,则不需要COM或不可靠的解决方法:只需运行文件夹

Run C:\delete#me
如果要在已激活的现有窗口中打开路径,最简单和最有效的解决方法是:

SendInput {F4}{Esc}{Raw}C:\delete#me`n
因此,在脚本的上下文中,您可以使用以下函数来解决
出现时的问题:

导航(pExp,myPath2)
;...
导航(Exp,Path)
{
如果RegExMatch(路径“#。*\\”)
SendInput{F4}{Esc}{Raw}%Path%`n
其他的
Exp.Navigate(路径)
}

当我看到Navigate无法处理哈希时,我感到震惊, 但我确实复制了这个错误。 我想我应该试试短路径,以防万一。它起作用了

if vDir contains #
Loop, %vDir%, 2, 0 ;(0/1/2=files/both/folders, 0/1=recurse no/yes)
vDir := A_LoopFileShortPath
  • 以下方法不需要可见的地址栏或SendInput, 还将保留以前的导航历史记录
  • 在最坏的情况下,目标目录上方目录的短路径中出现哈希, 使用导航到的中间文件夹
  • 在那里创建、调用和删除链接
  • 下面缩进了变通代码,以将其与标准代码分开
  • 当资源管理器窗口处于活动状态时,ctrl+q热键将启动脚本
-


我有一个看起来很有效的解决方案,我也在这里发布了:

在Windows资源管理器中更改当前文件夹的4个选项-第3页-自动热键社区


您已标记此自动热键。为什么需要com对象来导航windows资源管理器?这在“收藏夹”应用程序中用于将windows资源管理器导航到选定的收藏夹。也许您知道AutoHotkey是一种宏语言。这也是一个非常强大的便携式应用程序开发工具。我刚刚在你的个人资料中看到,你已经非常了解AHK:-)我正在使用Shell命令来确保应用程序在任何语言环境下都能工作。依靠界面来更改文件夹在Windows int'l实现中是有风险的。对我来说,它打开了我的webbrowser…你好,Joe。仅使用Alt-2或同时使用两种路径?在打开新窗口的特定情况下,您只需
运行C:\delete\me
。是的,您是对的。这个场景是当你想“导航”当前浏览器到另一个文件夹时。对于那些感兴趣的人,我邀请你跳到这个线程中,Lexikos正在探索各种选项:是的。你的代码比我上一个答案中的代码好。如果使用原始选项,则不需要ControlSetText。但是如果没有#,您是否同意使用COM更好地导航当前的资源管理器?这应该比向前端发送击键更快,可能更可靠。正如您所说,调用Navigate()更快、更可靠,如果可以的话。激活地址栏(F4)也会引起一些“视觉干扰”。乍一看,我喜欢你的解决方案。不幸的是,当#是文件夹名称前6个字符的一部分时,它将不起作用。在这种情况下,短格式名称仍将包含#并导致错误。示例1正常1=C:\abc xyz超长文件夹#名称\abc 2=C:\abc-XY~1\abc//示例2不起作用:1=C:\abc#xyz超长文件夹名称\abc 2=C:\abc#XY~1\abc谢谢,从DOS时代起,我就记不起短格式是否只有字母数字和波浪形。我在另一个论坛上说过:也许可以为带有哈希的文件夹分配一个特殊的文件夹ID,然后将其放入Navigate()。一个类似于“shell:Desktop”的特殊ID。此ID有效:)。。这应该是答案。在Windows 10 build 18363上测试
SendInput {F4}{Esc}{Raw}C:\delete#me`n
if vDir contains #
Loop, %vDir%, 2, 0 ;(0/1/2=files/both/folders, 0/1=recurse no/yes)
vDir := A_LoopFileShortPath
^q:: ;explorer - navigate to directory (use go-between dir if short-form path of dir above target contains #)
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass not in CabinetWClass,ExploreWClass
Return

vDir2 = %A_Desktop%\Go-Between ;go-between dir
vDir3 = C:\delete#me ;target dir

if (SubStr(vDir3, 1-1) = "\")
vDir3 := SubStr(vDir3, 1, -1)
if !InStr(FileExist(vDir3), "D")
Return

    vPathLnk := ""

    if vDir3 contains #
    Loop, %vDir3%, 2, 0 ;(0/1/2=files/both/folders, 0/1=recurse no/yes)
    vDir3 := A_LoopFileShortPath

    ;vDir4 is the short-form path of the dir above the target
    ;paths of problem target dirs are of the form: *#*\*
    ;where there is at least one hash with a backslash to its right
    SplitPath, vDir3, , vDir4
    if vDir4 contains #
    {
    if !InStr(FileExist(vDir2), "D")
    FileCreateDir, %vDir2%
    if !InStr(FileExist(vDir2), "D")
    {
    MsgBox error`, go-between dir not found:`r`n%vDir2%
    Return
    }
    vNameLnk = Go-Between.lnk
    vPathLnk = %vDir2%\%vNameLnk%
    FileCreateShortcut, %vDir3%, %vPathLnk%
    }

for oWin in ComObjCreate("Shell.Application").Windows
if (hWnd = oWin.Hwnd)
{
vDir1 := oWin.Document.Folder.Self.Path
if (vDir1 = vDir3)
break

    if vDir3 contains #
    {
    if !(vDir1 = vDir2)
    oWin.Navigate(vDir2)
    while !(oWin.ReadyState = 4)
    Sleep 10

    oItem := oWin.Document.Folder.Items.Item(vNameLnk)
    oItem.InvokeVerbEx("open")
    break
    }

oWin.Navigate(vDir3)
break
}

oWin := ""

    if !(vPathLnk = "")
    FileRecycle, %vPathLnk% ;send to recycle bin
    ;if !(vPathLnk = "")
    ;FileDelete, %vPathLnk% ;delete
Return
;links:
;Explorer Windows Manipulations - Page 5 - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/19039-explorer-windows-manipulations/page-5#entry297581
;Navigate2 Method (IWebBrowser2)
;https://msdn.microsoft.com/en-us/library/aa752134(v=vs.85).aspx
;4 options to change the current folder in Windows Explorer - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=526
;windows - Navigate Shell command not working when the path includes an hash - Stack Overflow
;https://stackoverflow.com/questions/22868546/navigate-shell-command-not-working-when-the-path-includes-an-hash

;an AutoHotkey v1.1 script
;note: will create folder: %A_Desktop%\abc#def\abc#def
;q:: ;explorer - navigate to folder (tested on Windows 7)
WinGet, hWnd, ID, A
WinGetClass, vWinClass, % "ahk_id " hWnd
if !(vWinClass = "CabinetWClass") && !(vWinClass = "ExploreWClass")
    return

vDir = %A_Desktop%\abc#def\abc#def
;vDir = %A_Desktop%\abc def\abc def
if !FileExist(vDir)
    FileCreateDir, % vDir

DllCall("shell32\SHParseDisplayName", WStr,vDir, Ptr,0, PtrP,vPIDL, UInt,0, Ptr,0)
for oWin in ComObjCreate("Shell.Application").Windows
    if (oWin.HWND = hWnd)
    {
        if !InStr(vDir, "#")
            oWin.Navigate(vDir)
        else
        {
            VarSetCapacity(SAFEARRAY, A_PtrSize=8?32:24, 0)
            NumPut(1, SAFEARRAY, 0, "UShort")
            NumPut(1, SAFEARRAY, 4, "UShort")
            NumPut(vPIDL, SAFEARRAY, A_PtrSize=8?16:12, "Ptr")
            NumPut(DllCall("shell32\ILGetSize", Ptr,vPIDL, UInt), SAFEARRAY, A_PtrSize=8?24:16, "Int")
            oWin.Navigate2(ComObject(0x2011,&SAFEARRAY))
            DllCall("shell32\ILFree", Ptr,vPIDL)
        }
        break
    }
return