4 options to change the current folder in Windows Explorer

Post a reply


In an effort to prevent automatic submissions, we require that you type the text displayed into the field underneath.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 4 options to change the current folder in Windows Explorer

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

Post by qwerty12 » 13 Jun 2017, 16:00

Interesting... Thanks, jeeswg

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

Post by jeeswg » 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] [Expand]GeSHi © Codebox Plus

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

Post by jeeswg » 30 Dec 2016, 00:58

you can navigate from folder 1 to 2 by creating and invoking a lnk file inside folder 1,
if you can't create a lnk in the protected/special folder,
you could navigate to a go-between folder and create the lnk there,
I don't know of a way to check whether the current folder is protected/special or not,
so I could just always use the go-between folder

anyway you've got me hooked on this problem,
I posted some code at the Stack Overflow link

anyway this Navigate instruction, they really made a hash of it

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

Post by jeeswg » 27 Dec 2016, 13:44

OK, unfortunately still a problem if the folder has a # in the first 6 characters of any of the subfolder names. Is it possible to assign a special folder ID to the folder with the hash, and then put that into Navigate()?

e.g. shell:Desktop

[EDIT:]
Or perhaps IShellBrowser::BrowseObject with a PIDL?

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

Post by jeeswg » 27 Dec 2016, 00:32

When I saw that Navigate couldn't handle hash, I was shocked,
but sure enough I replicated the error.
I thought I'd try the short form path just in case. It works!

Code: [Select all]GeSHi © Codebox Plus

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

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

Post by JnLlnd » 06 Sep 2014, 22:47

Hum... Interesting. So much work for something that should just be working in the first time... I suppose this is not the first time you have to work that hard around a Windows bug :-)

I adapted my code to use SendInput command with {Raw} option instead of the ControlSetText approach that is now irrelevant. I also use your regex instead of a simple InStr. This will limit the use of the workaround to the cases where there is a \ after the #.

Being on StackOverflow, I would definitively + your answer :-)

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

Post by lexikos » 06 Sep 2014, 19:56

So, one limited workaround is to open a base folder and navigate to each sub folder. For example (call this instead of pExp.Navigate()):

Code: [Select all] [Expand]GeSHi © Codebox Plus


Unfortunately, this won't work as intended if the user has Explorer set to open each folder in a separate window. For that case, you could Run %Path% and close the old window:

Code: [Select all] [Expand]GeSHi © Codebox Plus

This would need adjustment for systems without the "Display the full path in the title bar" option enabled.

Although Run %Path% should be reliable, it discards the (back/forward) history. Assuming you already have an Explorer window in the foreground that you want to open the folder in, this approach seems to be fairly reliable:

Code: [Select all]GeSHi © Codebox Plus

Navigate(Exp, Path)
{
if RegExMatch(Path, "#.*\\")
SendInput {F4}{Esc}{Raw}%Path%`n
else
Exp.Navigate(Path)
}

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

Post by lexikos » 06 Sep 2014, 18:47

Apparently it only works if there is no slash after the hash. (Edit: Reading your Stack Overflow post, I see you already figured that out.)

Would it be related to # being a special AHK char?
# is special only for Send and hotkeys. No character in a quoted literal string has special meaning, except ` and ".

When a message box from "Windows Explorer" appears saying that it cannot find "file:///C:/delete#me/", that clearly shows that Windows Explorer is showing the error message, not AutoHotkey, and that Windows Explorer received the proper file path, since it is shown in the error message. One can therefore conclude that the problem lies with Windows Explorer.

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

Post by JnLlnd » 05 Sep 2014, 07:23

lexikos wrote:Your Send code fails because # is the modifier symbol for the Win key. You can use {#} or SendRaw c:\delete#me`n (not {Enter}) instead.
Thanks for jumping in Lekikos. Yes, I realized that later in my AHK learning curve :-) . Just forgot to update this thread about it.

lexikos wrote:However, window.Navigate("C:\C#Projects") works just fine for me on Windows 7.
You script also worked for me (after I adapted window.LocationName = "Computer" to my environment. But could you try the following and tell me if Alt-2 is running well for you? For me, it still produced an error. Would it be related to # being a special AHK char?

Code: [Select all] [Expand]GeSHi © Codebox Plus

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

Post by lexikos » 05 Sep 2014, 05:39

JnLlnd, I came across your posts while searching for something else, and thought I'd look into your issue. However, window.Navigate("C:\C#Projects") works just fine for me on Windows 7. It also works with "file:///C:/C#Projects". Your Send code fails because # is the modifier symbol for the Win key. You can use {#} or SendRaw c:\delete#me`n (not {Enter}) instead.

Code: [Select all]GeSHi © Codebox Plus

; Test script: navigate the "Computer" window to a path containing #.
FileCreateDir C:\C#Projects
for window in ComObjCreate("Shell.Application").Windows
try
if window.LocationName = "Computer"
window.Navigate("C:\C#Projects")

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

Post by JnLlnd » 23 Apr 2014, 19:14

Trying this with a folder name including # did not work! (EDIT: See foot note)

This works:

Code: [Select all]GeSHi © Codebox Plus

run, Explorer.exe
Sleep, 500
Send, {F4}{Esc}
Sleep, 500
Send, c:\delete_me{Enter}

But this does not work: (EDIT: See foot note)

Code: [Select all]GeSHi © Codebox Plus

run, Explorer.exe
Sleep, 500
Send, {F4}{Esc}
Sleep, 500
Send, c:\delete#me{Enter}

The only difference is the _ replaced by # ! It looks like Windows Explorer really have problem with hash in folder names.

Finally, the only way I found to make this work is:

Code: [Select all]GeSHi © Codebox Plus

run, Explorer.exe
Sleep, 500 ; long delay for safety
strFolder := A_ScriptDir
Send, {F4}{Esc}
Sleep, 500 ; long delay for safety
ControlSetText, Edit1, C:\delete#me, A
ControlSend, Edit1, {Enter}, A


I could not give the rational behind this...

EDIT (2014-09-06): Send, c:\delete#me does not work only because # is a AHK special character when used with Send. The command works if you add the {Raw} option: Send, {Raw}c:\delete#me. See comments from Lexikos belo for more about this.

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

Post by JnLlnd » 23 Apr 2014, 16:53

Unfortunately, there does not seem to be a solution to this:

Code: [Select all]GeSHi © Codebox Plus

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).

The workaround would be to rely on the "second best" approach as identified by the tests in this thread: Explorer_F4Esc. For example (when Explorer is the active window):

Code: [Select all]GeSHi © Codebox Plus

Send, {F4}{Esc}
Sleep, 500 ; long delay for safety
Send, %strFolder%{Enter}

Navigate Shell command not working when the path includes ha

Post by JnLlnd » 04 Apr 2014, 11:57

Hello!

I'm having problem using the Navigate Shell command when the path include an # sign (search keywords: hashtag, number sign or pound).

I posted the question on StackOverflow:
http://stackoverflow.com/questions/2286 ... es-an-hash

You could reply here or on StackOverflow.

Thanks!

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

Post by Azevedo » 09 Feb 2014, 13:56

Yes thanks,

Although I'm building it to myself I do want to be reliable and steady.
So I'm using ControlGetText and ControlSetText. I really do the trick!

Now the problem is with old Open/Save dialog boxes (which have simple combo box to navigate). It won't allow directly changing to a folder that is not in that combo box.

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

Post by JnLlnd » 09 Feb 2014, 10:54

Just to make my comment more clear, you can use command like ControlGetText and ControlSetText to save and change the current dialog box folder. The Send key itself is used only to press "Enter". This could be relatively simple. But the longer approach described by Learning One in viewtopic.php?f=5&t=526&start=20#p4673 is much safer.

Of course, if you are doing something for yourself (I mean, you don't plan to distribute your code to other users), you could work this out using only Send and Sleep commands.

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

Post by Azevedo » 07 Feb 2014, 19:57

The Shell.Application COM object is only opening or controling Explorr windows. For dialog boxes, you have to send commands to dialog box control and Send some keys.

See this script and search for NavigateDialog(strPath, strWinId, strClass) close to the end of the script.

Here is an abstract of the code (this will not work by itself but you have the ingredients):


Oh I see... well ok, I'll do with the send commands then!

Thanks a lot!

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

Post by JnLlnd » 07 Feb 2014, 18:55

Azevedo wrote:Hi.
It works fine on a regular windows explorer window but it won't work on Open/Save dialogs.
Any help?

Thanks


The Shell.Application COM object is only opening or controling Explorr windows. For dialog boxes, you have to send commands to dialog box control and Send some keys.

See this script and search for NavigateDialog(strPath, strWinId, strClass) close to the end of the script.

Here is an abstract of the code (this will not work by itself but you have the ingredients):

Code: [Select all] [Expand]GeSHi © Codebox Plus



See also this thread viewtopic.php?f=5&t=526&start=20#p4673

Good luck!

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

Post by fischgeek » 07 Feb 2014, 12:42

Works great on 8.1. No modifications.

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

Post by Azevedo » 07 Feb 2014, 11:40

Hi.
About this code...

Code: [Select all]GeSHi © Codebox Plus

		location := "c:\windows"
WinGet, hwnd_id, ID, A
msgbox % hwnd_id

For pExp in ComObjCreate("Shell.Application").Windows
if (pExp.hwnd = hwnd_id) ; matching window found
pExp.Navigate(location)

It works fine on a regular windows explorer window but it won't work on Open/Save dialogs.
Any help?

Thanks

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

Post by JnLlnd » 22 Nov 2013, 22:50

Final beta version of my new app is now released. Just decided to rename to "Folders Popup" it in the last minute (what a crazy idea!).

Apps source: https://github.com/JnLlnd/FoldersPopup
Apps home page: http://code.jeanlalonde.ca/folderspopup/

Thank you all for your help (as mentioned in the app's About page).

Top