当路径包含一个#符号时,我在使用导航Shell命令时遇到了问题。
; this will create 2 folders at the root of your C: drive
myPath1 := "C:\delete_me\"
myPath2 := "C:\delete#me\"
if !FileExist(myPath1)
FileCreateDir, %myPath1%
if !FileExist(myPath2)
FileCreateDir, %myPath2%
; make an Explorer active and press Alt-1 and Alt-2
return
!1::
strWinId := WinExist("A")
TrayTip, %myPath1%, %strWinId%
For pExp in ComObjCreate("Shell.Application").Windows
if (pExp.hwnd = strWinId)
try pExp.Navigate(myPath1)
return
!2::
strWinId := WinExist("A")
TrayTip, %myPath2%, %strWinId%
For pExp in ComObjCreate("Shell.Application").Windows
if (pExp.hwnd = strWinId)
try pExp.Navigate(myPath2)
returnAlt-1很好用。但是,在Alt-2中,导航命令返回“file:///C:/delete#me/ command ? not”。
如果在"#“之后没有"/”(如myPath := "C:\delete#me"),它就会工作。但这不可能是一个解决方案,因为目标路径可能在子文件夹中更深(例如。"C:\delete#me\xyz")。
我试图对"#“进行编码,将其替换为"%23",但没有成功。在网络或MSDN上没有发现任何关于这一点的信息。有什么想法吗?
关键词: haskmark,hashtag,数字符号或磅
发布于 2014-09-08 05:58:04
如果您想打开一个新窗口,就不需要COM或不可靠的解决方案:只需运行文件夹即可。
Run C:\delete#me如果要在已处于活动状态的现有窗口中打开路径,最简单和最有效的解决方法是:
SendInput {F4}{Esc}{Raw}C:\delete#me`n因此,在脚本的上下文中,当#出现时,您可以使用以下函数来绕过它:
Navigate(pExp, myPath2)
;...
Navigate(Exp, Path)
{
if RegExMatch(Path, "#.*\\")
SendInput {F4}{Esc}{Raw}%Path%`n
else
Exp.Navigate(Path)
}发布于 2017-06-13 20:57:33
我有一个看起来是可行的解决方案,我也在这里发布了:
更改Windows中当前文件夹的4个选项-第3页- AutoHotkey社区
https://autohotkey.com/boards/viewtopic.php?f=5&t=526&p=153676#p153676
;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发布于 2014-04-24 00:16:41
不幸的是,似乎没有解决这个问题的办法。如果路径包含散列(如C:\C#Projects中的#),则C:\C#Projects导航命令将失败。
使用AutoHotkey,解决方法将依赖于这个线程中的测试所确定的“第二最佳”方法:http://ahkscript.org/boards/viewtopic.php?f=5&t=526。
run, Explorer.exe
Sleep, 500
strFolder := A_ScriptDir
Send, {F4}{Esc}
Sleep, 500
ControlSetText, Edit1, C:\delete#me, A
ControlSend, Edit1, {Enter}, Ahttps://stackoverflow.com/questions/22868546
复制相似问题