Page 2 of 3

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

Posted: 06 Mar 2018, 16:13
by JoPo
Jeeswg --> With your script, I just go in the parent folder, then stop ! No good ! No good ! :mrgreen:

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

Posted: 06 Mar 2018, 18:09
by teadrinker
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?

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

Posted: 06 Mar 2018, 20:11
by JoPo
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...

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

Posted: 08 Mar 2018, 13:39
by JoPo
Ah... It certainly means that it's not possible. Thanks anyway for your help !

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

Posted: 27 Oct 2020, 16:03
by monkey5465
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)
}

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

Posted: 11 Oct 2021, 04:15
by koolestani
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

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

Posted: 11 Oct 2021, 05:57
by teadrinker
I suppose the issue is here: vGetNext := !!InStr(A_ThisHotkey, "Dn").

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

Posted: 20 Oct 2021, 04:04
by koolestani
i'm sorry i don't get it, where exactly you are suggesting me to insert vGetNext := !!InStr(A_ThisHotkey, "Dn") ?

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

Posted: 20 Oct 2021, 06:00
by teadrinker
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")

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

Posted: 20 Oct 2021, 07:00
by koolestani
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

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

Posted: 20 Oct 2021, 08:34
by teadrinker
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.

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

Posted: 20 Oct 2021, 08:58
by koolestani
ahh my bad, can you please elaborate on the difference for me.

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

Posted: 20 Oct 2021, 09:42
by teadrinker
Just launch this script, press all the hotkeys one by one and see what message boxes will show.

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

Posted: 20 Oct 2021, 12:30
by koolestani
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?

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

Posted: 20 Oct 2021, 12:44
by teadrinker
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.

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

Posted: 20 Oct 2021, 13:12
by koolestani
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") )

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

Posted: 20 Oct 2021, 13:57
by teadrinker
Fine! :thumbup:

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

Posted: 08 Dec 2021, 12:27
by sachin24
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)
}

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

Posted: 08 Dec 2021, 12:30
by sachin24
How to make it work in Save, Save As & Open Window i.e. ahk_class #32770 ????
Kindly help :)

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

Posted: 08 Dec 2021, 13:28
by teadrinker
These windows are not shell windows, this code won't work with them.