Page 1 of 1

Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 17 Apr 2019, 11:21
by jwinfl
How do I Highlight an existing Folder (using it's Name or Path) in the active Windows 10 Explorer window?

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 17 Apr 2019, 13:26
by Tigerlily
jwinfl wrote:
17 Apr 2019, 11:21
How do I Highlight an existing Folder (using it's Name or Path) in the active Windows 10 Explorer window?

try this:

Code: Select all

filepath := "C:\Users\User\Desktop\YourFile.txt"
Run, % "explorer /select, " filepath

:arrow: Explorer docs for more info

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 17 Apr 2019, 19:03
by jeeswg
- Some ideas (set the focus/selection):
Explorer window interaction (folder windows/Desktop, file/folder enumeration/selection/navigation/creation) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=35041
- Nice link Tigerlily. Cheers.

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 18 Apr 2019, 09:36
by jwinfl
Tigerlily,
Thanks for the response.
I wanted to highlight the folder (filepath) in the ACTIVE (already existing) Explorer window, if possible.
Run, % "explorer /select, " filepath ... opens a NEW Explorer window (does NOT use the existing window).
If you know how to select the file in the existing Explorer window (I have the title & wHandle), I would appreciate it.
Thank You
Jack

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 18 Apr 2019, 10:53
by Klarion
easy

First, get the information
Now, close it
Lastly, open it with the information you have as above mentioned tips

right ?

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 19 Apr 2019, 08:36
by jwinfl
Klarion,
Thank you, but I already knew how to make Tigerlily's code work, unfortunately, I want to use the active window not a new one.
There are many reasons, including, the active windows set up, screen location, etc. which are being controlled by other programs.
Yes, all of these can be redone to the new window but I would prefer not to reinvent the wheel here.
If there is a simple way to highlight the folder name specified in the active explorer window, great, if not, it is not worth the time and effort to change my code to work with a the new window.
Thank You
Jack

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window  Topic is solved

Posted: 19 Apr 2019, 09:03
by Odlanir
In the link posted by jeeswg you can find the Function which set the focus in the current Explorer window.
Usage:
press q to hilight the requested file or folder.
press esc to exit.

Code: Select all

;~ From : ;~ https://www.autohotkey.com/boards/viewtopic.php?f=6&t=35041
#SingleInstance, force
#Persistent

~q::
JEE_ExpWinSetFoc(0, "NameOfyourFileOrFolder")
return 

ExitApp

JEE_ExpWinSetFoc(hWnd, vName, vByPos:=0, vFlags:=0x1D)
{
	local oItems, oWin, oWindows, vWinClass
	DetectHiddenWindows, On
	(!hWnd) && hWnd := WinExist("A")
	WinGetClass, vWinClass, % "ahk_id " hWnd
	if (vWinClass = "CabinetWClass") || (vWinClass = "ExploreWClass")
	{
		for oWin in ComObjCreate("Shell.Application").Windows
			if (oWin.HWND = hWnd)
				break
	}
	else if (vWinClass = "Progman") || (vWinClass = "WorkerW")
	{
		oWindows := ComObjCreate("Shell.Application").Windows
		VarSetCapacity(hWnd, 4, 0)
		;SWC_DESKTOP := 0x8 ;VT_BYREF := 0x4000 ;VT_I4 := 0x3 ;SWFO_NEEDDISPATCH := 0x1
		oWin := oWindows.FindWindowSW(0, "", 8, ComObject(0x4003, &hWnd), 1)
	}
	else
		return

	oItems := oWin.Document.Folder.Items
	;SVSI_FOCUSED = 0x10 ;SVSI_ENSUREVISIBLE := 0x8
	;SVSI_DESELECTOTHERS := 0x4 ;SVSI_EDIT := 0x3
	;SVSI_SELECT := 0x1 ;SVSI_DESELECT := 0x0
	if !vByPos
		oWin.Document.SelectItem(oItems.Item(vName), vFlags)
	else
		oWin.Document.SelectItem(oItems.Item(vName-1), vFlags)
	oWindows := oWin := oItems := ""
}
esc::
    ExitApp

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 20 Apr 2019, 07:36
by jwinfl
Odlanir,
Thank you for the code.
I added; JEE_ExpWinSetFoc(0, "NameOfyourFileOrFolder") to my code (no hotkey)
and the function; JEE_ExpWinSetFoc(hWnd, vName, vByPos:=0, vFlags:=0x1D)
It works exactly as I had hoped.
Thanks again.
Jack

Re: Highlight a Folder (by Name or Path) in the active Windows 10 Explorer window

Posted: 20 Apr 2019, 07:46
by Odlanir
Nice, but you should tank jeeswg who is the author.