Re: How to navigate to next sibling folder from Windows Explorer?
Posted: 06 Mar 2018, 16:13
Jeeswg --> With your script, I just go in the parent folder, then stop ! No good ! No good !
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=40200
JoPo wrote:I would like, is a script that would allow me to go int the previous / next folder, if the parent folder is alone, go in the next parent folder and repeat the same untill to find a folder amonst others and directly going into it.
Code: Select all
#If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass")
^PgUp::
^PgDn:: NavigateToSiblingDir( InStr(A_ThisHotkey, "Up") )
NavigateToSiblingDir(UpDown) {
oShell := ComObjCreate("Shell.Application")
WinGet, hWnd,, A
for oWin in oShell.Windows {
if (hWnd = oWin.hwnd) {
oFolder := oWin.Document.Folder
startDirPath := oFolder.Self.Path
parentDirPath := oFolder.ParentFolder.Self.Path
break
}
}
while parentDirPath {
for item in oShell.Namespace(parentDirPath).Items {
if !item.IsFolder
continue
if (found && nextSiblingPath := item.Path)
break
if (item.Path = startDirPath && found := true)
prevSiblingPath := prev
prev := item.Path
}
if (prevSiblingPath || nextSiblingPath)
break
oFolder := oFolder.ParentFolder
startDirPath := oFolder.Self.Path
parentDirPath := oFolder.ParentFolder.Self.Path
flag := true, found := prev := ""
}
(flag && prevSiblingPath := nextSiblingPath := oFolder.Self.Path)
( (UpDown && (navigatePath := prevSiblingPath)) || (!UpDown && (navigatePath := nextSiblingPath)) )
if navigatePath {
DllCall("shell32\SHParseDisplayName", WStr, navigatePath, Ptr,0, PtrP,vPIDL, UInt,0, Ptr,0)
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), 0)
DllCall("shell32\ILFree", Ptr,vPIDL)
}
}
I'm not sure if I understand what you mean. If the next sibling has many subfolders, which subfolder should the script navigate into?JoPo wrote:I gonna add some difficulty... Eh eh... If the script would allow me to do what I explained + going in the next / previous sibling folder untill it reaches the latest folder (in which there are only files = no more folder to continue to go in) , it would be like heaven !!
Code: Select all
; navigate to next sibling folder from Windows Explorer
#If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass")
^PgUp::
^PgDn:: NavigateToSiblingDir( InStr(A_ThisHotkey, "Up") )
NavigateToSiblingDir(UpDown) {
oShell := ComObjCreate("Shell.Application")
WinGet, hWnd,, A
for oWin in oShell.Windows {
if (hWnd = oWin.hwnd) {
oFolder := oWin.Document.Folder
startDirPath := oFolder.Self.Path
parentDirPath := oFolder.ParentFolder.Self.Path
break
}
}
for item in oShell.Namespace(parentDirPath).Items {
if !item.IsFolder
continue
if (found && nextSiblingPath := item.Path)
break
if (item.Path = startDirPath && found := true)
prevSiblingPath := prev
prev := item.Path
}
if (UpDown && prevSiblingPath)
oWin.Navigate(prevSiblingPath)
if (!UpDown && nextSiblingPath)
oWin.Navigate(nextSiblingPath)
}
Code: Select all
^PgUp:: MsgBox, % vGetNext := !!InStr(A_ThisHotkey, "Dn")
^PgDn:: MsgBox, % vGetNext := !!InStr(A_ThisHotkey, "Dn")
XButton1 & LButton:: MsgBox, % vGetNext := !!InStr(A_ThisHotkey, "Dn")
XButton1 & RButton:: MsgBox, % vGetNext := !!InStr(A_ThisHotkey, "Dn")
But I didn't suggest adding this code. I suggest to understand what the difference is between the initial pair of hotkeys and those you want to implement.koolestani wrote: ↑i tried adding this code you suggested
See in docs what the InStr() function does, think how to change its call to get XButton1 & RButton returning 1.koolestani wrote: ↑it's very weird that this is happening
teadrinker wrote: ↑19 Nov 2017, 15:35It's a bit confusing.
For me this works:Code: Select all
#If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") ^PgUp:: ^PgDn:: NavigateToSiblingDir( InStr(A_ThisHotkey, "Up") ) NavigateToSiblingDir(UpDown) { oShell := ComObjCreate("Shell.Application") WinGet, hWnd,, A for oWin in oShell.Windows { if (hWnd = oWin.hwnd) { oFolder := oWin.Document.Folder startDirPath := oFolder.Self.Path parentDirPath := oFolder.ParentFolder.Self.Path break } } for item in oShell.Namespace(parentDirPath).Items { if !item.IsFolder continue if (found && nextSiblingPath := item.Path) break if (item.Path = startDirPath && found := true) prevSiblingPath := prev prev := item.Path } if (UpDown && prevSiblingPath) oWin.Navigate(prevSiblingPath) if (!UpDown && nextSiblingPath) oWin.Navigate(nextSiblingPath) }