Reputation: 21
I have an opened folder:
"C:\Users\Me\Desktop\Named_Folder"
==================================
Under "Named_Folder" there is folder called "1" and under that folder there is another one called "2".
I want to create a one letter shortcut to go from active "Named_Folder" to folder "2" so the path would look like this:
"C:\Users\Me\Desktop\Named_Folder\1\2"
Here i need to mention that folder "1" and "2" have always the same name, but "Named_Folder" has always a different name.
So maybe I could improve this topic title: Go 2 directories down from active directory with one letter shortcut ?
Upvotes: 0
Views: 1128
Reputation: 10543
#If WinActive("ahk_class CabinetWClass") ; explorer
F1::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
; IfExist, %Fullpath%\1\
Run, %Fullpath%\1
return
F2::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
; IfExist, %Fullpath%\1\2\
Run, %Fullpath%\1\2
return
#If
EDIT: navigating to a directory without opening a new window:
#If WinActive("ahk_class CabinetWClass") ; explorer
F1::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
IfExist, %Fullpath%\1\
NavRun( Fullpath "\1")
return
F2::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := window.Document.Folder.Self.Path
IfExist, %Fullpath%\1\2\
NavRun( Fullpath "\1\2")
return
#If
; http://msdn.microsoft.com/en-us/library/bb774094
GetActiveExplorer() {
static objShell := ComObjCreate("Shell.Application")
WinHWND := WinActive("A") ; Active window
for Item in objShell.Windows
if (Item.HWND = WinHWND)
return Item ; Return active window object
return -1 ; No explorer windows match active window
}
NavRun(Path) {
if (-1 != objIE := GetActiveExplorer())
objIE.Navigate(Path)
else
Run, % Path
}
https://autohotkey.com/board/topic/102127-navigating-explorer-directories/#entry634365
Upvotes: 1