4 options to change the current folder in Windows Explorer
- JnLlnd
- Posts: 326
- Joined: 29 Sep 2013, 21:29
- GitHub: JnLlnd
- Location: Montreal, Quebec, Canada
- Contact:
Re: 4 options to change the current folder in Windows Explorer
Thanks for the references, jeeswg. I used Navigate2 with an integer parameter (for example 17 = My Computer) but I did not know about object parameters. Interesting.



Re: 4 options to change the current folder in Windows Explor
Just registered to say THANK YOU!! for all this fundamental research you all have done.
Very valuable, as I''m writing my first AHK (to navigate to folders using Everything, a very reliable and fast file/folder search utility). This thread helps enormously with that
BTW:
Very valuable, as I''m writing my first AHK (to navigate to folders using Everything, a very reliable and fast file/folder search utility). This thread helps enormously with that

BTW:
No (longer?) such problems with AHK 1.1.27.07 @ Win10 1709 (both x64)JnLlnd wrote:Unfortunately, there does not seem to be a solution to this:
This will fail if myPath includes a hash (# as in C:\C#Projects).Code: Select all
For pExp in ComObjCreate("Shell.Application").Windows if (pExp.hwnd = strWinId) try pExp.Navigate(myPath)
- JnLlnd
- Posts: 326
- Joined: 29 Sep 2013, 21:29
- GitHub: JnLlnd
- Location: Montreal, Quebec, Canada
- Contact:
Re: 4 options to change the current folder in Windows Explorer
Hi Eureka,
Please read this post and the following:
https://autohotkey.com/boards/viewtopic ... 199#p25199
For me, it still does not work if there is a slash after the hash. My message and example should have been: "This will fail if myPath includes a hash and has a slash after it (as in C:\C#Projects\)."
Please read this post and the following:
https://autohotkey.com/boards/viewtopic ... 199#p25199
For me, it still does not work if there is a slash after the hash. My message and example should have been: "This will fail if myPath includes a hash and has a slash after it (as in C:\C#Projects\)."



Re: 4 options to change the current folder in Windows Explorer
Ah, I see. Same here ...JnLlnd wrote:Hi Eureka,
Please read this post and the following:
https://autohotkey.com/boards/viewtopic ... 199#p25199
For me, it still does not work if there is a slash after the hash. My message and example should have been: "This will fail if myPath includes a hash and has a slash after it (as in C:\C#Projects\)."
That's probably because this method uses the URL syntax. And a hash/pound/number sign has special meaning in that case.
I tried to replace it with it's URL escape character: %23 (*), but in that case the % was replaced by it's URL escape character (%25).
It should be possible to feed a literal % by escaping it in AHK, but I'm not (yet) experienced enough in AHK to get that working.
(*) Drag the foldername to the address bar of your browser to see the converted filename
Re: 4 options to change the current folder in Windows Explorer
Thanks a lot @jeeswg for your efforts and solutions you get tojeeswg wrote: ↑13 Jun 2017, 15:54I have what looks to be a working solution for this, which I've also posted here:
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
Code: Select all
;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") ;cDims NumPut(1, SAFEARRAY, 4, "UInt") ;cbElements NumPut(vPIDL, SAFEARRAY, A_PtrSize=8?16:12, "Ptr") ;pvData NumPut(DllCall("shell32\ILGetSize", Ptr,vPIDL, UInt), SAFEARRAY, A_PtrSize=8?24:16, "Int") ;rgsabound[1] oWin.Navigate2(ComObject(0x2011,&SAFEARRAY)) DllCall("shell32\ILFree", Ptr,vPIDL) } break } return


It's working efficiently with paths containing "#"

I've just packed in a simple function and all is working effectively:
Code: Select all
Explorer_Navigate(vDir, hWnd="") {
; WinGet, hWnd, ID, A
hWnd := (hWnd="") ? WinExist("A") : hWnd
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
}
Who is online
Users browsing this forum: bandel_nation, fiendhunter, leftclique, mikeyww, Odlanir, Rohwedder, songdg and 46 guests