4 options to change the current folder in Windows Explorer

Get help with using AutoHotkey and its commands and hotkeys
User avatar
JnLlnd
Posts: 310
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Re: 4 options to change the current folder in Windows Explorer

26 Jul 2017, 15:51

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.
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:clap: Quick Access Popup Knowledge base - Join our kind sponsors
:ugeek: Courses on AutoHotkey
Eureka
Posts: 18
Joined: 03 Apr 2018, 13:31
Location: Netherlands

Re: 4 options to change the current folder in Windows Explor

03 Apr 2018, 13:59

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:
JnLlnd wrote:Unfortunately, there does not seem to be a solution to this:

Code: Select all

For pExp in ComObjCreate("Shell.Application").Windows
    if (pExp.hwnd = strWinId)
        try pExp.Navigate(myPath)
This will fail if myPath includes a hash (# as in C:\C#Projects).
No (longer?) such problems with AHK 1.1.27.07 @ Win10 1709 (both x64)
User avatar
JnLlnd
Posts: 310
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Re: 4 options to change the current folder in Windows Explorer

03 Apr 2018, 16:44

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\)."
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:clap: Quick Access Popup Knowledge base - Join our kind sponsors
:ugeek: Courses on AutoHotkey
Eureka
Posts: 18
Joined: 03 Apr 2018, 13:31
Location: Netherlands

Re: 4 options to change the current folder in Windows Explorer

03 Apr 2018, 17:50

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\)."
Ah, I see. Same here ...
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
omareg94
Posts: 86
Joined: 27 Jun 2016, 22:46

Re: 4 options to change the current folder in Windows Explorer

27 Apr 2020, 07:22

jeeswg wrote:
13 Jun 2017, 15:54
I 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
Thanks a lot @jeeswg for your efforts and solutions you get to :) This really helps a lot :)
It's working efficiently with paths containing "#" :) .. Tested on Windows 10 build 18363


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
  }

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Dragoo, Epialis, jimhoyle, neo256, Sabestian Caine, unleashed7 and 46 guests