How to navigate to next sibling folder from Windows Explorer?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JoPo
Posts: 25
Joined: 04 Feb 2018, 09:03

Re: How to navigate to next sibling folder from Windows Explorer?

06 Mar 2018, 16:13

Jeeswg --> With your script, I just go in the parent folder, then stop ! No good ! No good ! :mrgreen:
> > > > > > > > > > > > --- Musica --> here ! ---< < < < < < < < < < < <
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

06 Mar 2018, 18:09

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)
   }
}
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 !! :o
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
Posts: 25
Joined: 04 Feb 2018, 09:03

Re: How to navigate to next sibling folder from Windows Explorer?

06 Mar 2018, 20:11

Ah ah ! Good question ! Only the first one, then the script can go to the following one, etc. Untill the last one and next key stroke, plaf ! It goes in the parent again untill it finds the first one with siblings... Like that, you'll explore all the folders one by one, deeply with just one key stroke.

I don't know if it's possible...
> > > > > > > > > > > > --- Musica --> here ! ---< < < < < < < < < < < <
JoPo
Posts: 25
Joined: 04 Feb 2018, 09:03

Re: How to navigate to next sibling folder from Windows Explorer?

08 Mar 2018, 13:39

Ah... It certainly means that it's not possible. Thanks anyway for your help !
> > > > > > > > > > > > --- Musica --> here ! ---< < < < < < < < < < < <
monkey5465
Posts: 1
Joined: 27 Oct 2020, 15:58

Re: How to navigate to next sibling folder from Windows Explorer?

27 Oct 2020, 16:03

Sorry to bring up this old tread. But can someone help me get this working with the "Save As" window to navigate the same way as this code works with Windows Explorer?
It works great when I'm using it in Windows Explorer, but I need the same functionality when saving a file in Photoshop. Being able to use ctrl-PgUp or PgDown to flip to the sibling folder when saving would be extremely helpful. Thanks so much!



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)
}
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

11 Oct 2021, 04:15

Can't get this to work when I replace ^PgUp and ^PgDn with XButton1 & LButton and XButton1 & RButton respectively. It keeps navigating to the next sibling folder with both hotkeys. Any ideas?
I'm talking about the code on the first page by jeeswg, really nice script otherwise :D :D
Last edited by koolestani on 20 Oct 2021, 12:33, edited 1 time in total.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

11 Oct 2021, 05:57

I suppose the issue is here: vGetNext := !!InStr(A_ThisHotkey, "Dn").
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 04:04

i'm sorry i don't get it, where exactly you are suggesting me to insert vGetNext := !!InStr(A_ThisHotkey, "Dn") ?
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 06:00

Try to understand what this line does:

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")
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 07:00

i should've probably mentioned this, i'm a noob in ahk, i tried adding this code you suggested, in the existing script and of course i couldn't make it work. All i get is dialog box with the message 0
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 08:34

koolestani wrote: i tried adding this code you suggested
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
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 08:58

ahh my bad, can you please elaborate on the difference for me.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 09:42

Just launch this script, press all the hotkeys one by one and see what message boxes will show.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 12:30

i see, upon pressing
^PgUp results in 0
^PgDn results in 1

but
XButton1 & LButton results in 0
XButton1 & RButton results in 0
it's very weird that this is happening, but it explains why the script you posted on the first page isn't working for me. any tips?
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 12:44

koolestani wrote: it's very weird that this is happening
See in docs what the InStr() function does, think how to change its call to get XButton1 & RButton returning 1.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: How to navigate to next sibling folder from Windows Explorer?

20 Oct 2021, 13:12

thanks for the help, i read up about the InStr() function and made the following changes and it worked
^PgUp::
^PgDn:: NavigateToSiblingDir( InStr(A_ThisHotkey, "Up") )

XButton1 & LButton::
XButton1 & RButton:: NavigateToSiblingDir( InStr(A_ThisHotkey, "L") )
sachin24
Posts: 9
Joined: 19 May 2020, 07:25

Re: How to navigate to next sibling folder from Windows Explorer?

08 Dec 2021, 12:27

How make it work in save / Open / Save As Window i.e. ahk_class #32770
teadrinker wrote:
19 Nov 2017, 15:35
It'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)
}
sachin24
Posts: 9
Joined: 19 May 2020, 07:25

Re: How to navigate to next sibling folder from Windows Explorer?

08 Dec 2021, 12:30

How to make it work in Save, Save As & Open Window i.e. ahk_class #32770 ????
Kindly help :)
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to navigate to next sibling folder from Windows Explorer?

08 Dec 2021, 13:28

These windows are not shell windows, this code won't work with them.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bubo_Bubo, mikeyww, OrangeCat, RussF and 134 guests