Page 1 of 2
Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 2:39 am
by BarryG
Is there a way to get a list of all open folders on the PC? Bearing in mind that Windows 11 has tabbed folders, too. I can get a list for non-tabbed folders in Win 10, but Win 11 is a nightmare. Anyone done this before?
I got this working for Win 10, but Win 11 doesn't have the "Address: " text so I can't detect folders on that OS.
Code: Select all
; https://www.purebasic.fr/english/viewtopic.php?p=572887#p572887
Global NewMap hWnd()
Procedure EnumChildProc(hWnd, lParam)
If Not FindMapElement(hWnd(), Str(hWnd))
GetWindowThreadProcessId_(hWnd, @PID)
WindowTitle.s = Space(999)
GetWindowText_(hWnd, @WindowTitle, 999)
lpClassName.s = Space(999)
GetClassName_(hWnd, @lpClassName, 999)
;If FindString(WindowTitle, "Address: ") And lpClassName="ToolbarWindow32" ; Shows folder paths on Win 10. :)
If lpClassName="ShellTabWindowClass" ; Shows folder NAMES for Win 11's tabbed folders, but not their paths. :(
AddGadgetItem(0, -1, "PID: " + Right("000" + Str(PID), 4) + " Window: " + Right("0000" + Hex(hWnd, #PB_Long), 8) + " " + #DQUOTE$ + WindowTitle + #DQUOTE$ + " " + lpClassName, 0, lParam + 1)
EndIf
hWnd(Str(hWnd))
EndIf
EnumChildWindows_(hWnd, @EnumChildProc(), lParam + 1)
ProcedureReturn #True
EndProcedure
If OpenWindow(0, 0, 0, 1000, 800, "Open Folders", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 980, 780, #PB_Tree_AlwaysShowSelection)
EnumChildWindows_(GetDesktopWindow_(), @EnumChildProc(), 0)
SetWindowTitle(0, "Enumerated Folders: " + Str(CountGadgetItems(0)))
SetGadgetItemState(0, 0, #PB_Tree_Expanded)
tvRoot = SendMessage_(GadgetID(0), #TVM_GETNEXTITEM, #TVGN_ROOT, 0)
SendMessage_(GadgetID(0), #TVM_SORTCHILDREN, #True, tvRoot)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 4:50 am
by AZJIO
Code: Select all
EnableExplicit
Global classText.s, instance
classText.s = Space(256)
Procedure enumChildren1(hwnd)
Protected pos
If hwnd
GetClassName_(hwnd, @classText, 256)
If classText = "ToolbarWindow32"
instance + 1
If instance = 3
GetWindowText_(hwnd, @classText, 256)
If Asc(classText)
pos = FindString(classText, ":")
If pos
Debug Mid(classText, pos + 2)
EndIf
ProcedureReturn 0
EndIf
EndIf
EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Procedure enumChildren0(hwnd)
If hwnd
GetClassName_(hwnd, @classText, 256)
If classText = "CabinetWClass"
instance = 0
EnumChildWindows_(hwnd, @enumChildren1(), 0)
EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
EnumChildWindows_(0, @enumChildren0(), 0)
No global variables
Code: Select all
EnableExplicit
Structure Paths
classText.s
instance.i
List Path.s()
EndStructure
Procedure enumChildren1(hwnd, *Paths.Paths)
Protected pos
If hwnd
GetClassName_(hwnd, @*Paths\classText, 256)
If *Paths\classText = "ToolbarWindow32"
*Paths\instance + 1
If *Paths\instance = 3
GetWindowText_(hwnd, @*Paths\classText, 256)
If Asc(*Paths\classText)
pos = FindString(*Paths\classText, ":")
If pos And AddElement(*Paths\Path())
*Paths\Path() = Mid(*Paths\classText, pos + 2)
If FileSize(*Paths\Path()) <> - 2
DeleteElement(*Paths\Path())
EndIf
EndIf
ProcedureReturn 0
EndIf
EndIf
EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Procedure enumChildren0(hwnd, *Paths.Paths)
If hwnd
GetClassName_(hwnd, @*Paths\classText, 256)
If *Paths\classText = "CabinetWClass"
*Paths\instance = 0
EnumChildWindows_(hwnd, @enumChildren1(), *Paths)
EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Define Paths.Paths
Paths\classText = Space(256)
EnumChildWindows_(0, @enumChildren0(), @Paths)
ForEach Paths\Path()
Debug Paths\Path()
Next
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 5:42 am
by RASHAD
Code: Select all
If lpClassName="SysTreeView32" ; Shows folder NAMES for Win 11's tabbed folders, but not their paths. :(
AddGadgetItem(0, -1, "PID: " + Right("000" + Str(PID), 4) + " Window: " + Right("0000" + Hex(hWnd, #PB_Long), 8) + " " + #DQUOTE$ + WindowTitle + #DQUOTE$ + " " + lpClassName, 0, lParam + 1)
EndIf
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 5:50 am
by BarryG
Thanks both of you for trying, but none of your codes work with Win 11, which is what I'm trying to do.
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 6:18 am
by AZJIO
WinInfo
Code: Select all
Select OSVersion()
Case #PB_OS_Windows_10
classText = "ToolbarWindow32"
instance = 3
Case #PB_OS_Windows_11
classText = "ToolbarWindow32???"
instance = ??
EndSelect
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 6:47 am
by BarryG
Nope, doesn't work because the folder class in Win 11 is "ShellTabWindowClass" but none of the items in the treeview in my first post have any actual paths associated with it, unlike Win 10. Win 11 is just making things harder.
Apparently this AutoHotkey code can get the current tab's folder path, but I have no idea how to make that work with Win 11 ->
https://www.autohotkey.com/boards/viewt ... 3&t=109907
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 7:49 am
by AZJIO
I checked for Win 11, make instance = 4

Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 8:11 am
by BarryG
Can you please post your full working snippet? But I'm also concerned that's it not working for me because you're still on 6.04 and your Win 11 folders aren't the tab type (there's no "+" after the title). Here's how my Win 11 folders look:
[Edit] Your screenshot is showing Win 10? I need this for Win 11.
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 8:33 am
by AZJIO
1. The picture shows Win11 (PE). If I open the folder in a new tab then the tabs appear. But since there is only one address bar with many tabs, it is obviously impossible to get the tab paths in this way.
2. The code does not contain any critical things on which the behavior of 604 and 610 would depend; I think the WinAPI call has not changed. I'm too lazy to check again on version 6.10, because I'm sure nothing will change.
BarryG wrote: Sat May 25, 2024 8:11 am
Can you please post your full working snippet?
Replace the string
on
BarryG wrote: Sat May 25, 2024 8:11 am
[Edit] Your screenshot is showing Win 10? I need this for Win 11.
On Win10 the corners are sharp and the icons are different
Add a debug line in different places and you will get the places where the stutter occurs
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 10:06 am
by BarryG
Changing the instance to 4 did nothing. I get no debug output at all, even with just one single folder open.

I tried different classes, too.
I think our versions of Win 11 must be different somehow. I always get the "+" at the end of a folder title, even if it's just one folder open.
This is my version:
AZJIO wrote: Sat May 25, 2024 8:33 amThe picture shows Win11 (PE).
I don't understand. This is what your screenshot shows. Your Win 11 folders are named after Win 10?
Re: Get list of all open folders (from Explorer windows)?
Posted: Sat May 25, 2024 3:18 pm
by AZJIO
Drive C: is named this way because Win10 is installed on it. And for the test I use LiveCD (boot.wim) with the Win11 operating system. I can take a screenshot of "Operating system properties", but tomorrow.
Add debugging and see if the paths are in the list. This will output all the lines in "ToolbarWindow32", not just "+".
Code: Select all
Procedure enumChildren1(hwnd, *Paths.Paths)
Protected pos
If hwnd
GetClassName_(hwnd, @*Paths\classText, 256)
If *Paths\classText = "ToolbarWindow32"
Debug *Paths\classText
Re: Get list of all open folders (from Explorer windows)?
Posted: Sun May 26, 2024 5:22 am
by BarryG
AZJIO wrote: Sat May 25, 2024 3:18 pmAdd debugging and see if the paths are in the list
No, they're not. I tried listing all parsed items with no filtering at all. And when I say "+", I mean in the folder's title bar itself; not from your PB code.
Which version of Win 11 do you have? Anyone else with Win 11 want to try this?
This is my latest test code, which returns no paths at all when dumping all items and not filtering anything.
Code: Select all
Structure Paths
classText.s
instance.i
List Path.s()
EndStructure
Procedure enumChildren1(hwnd, *Paths.Paths)
Protected pos
If hwnd
GetClassName_(hwnd, @*Paths\classText, 256)
;If *Paths\classText = "ToolbarWindow32"
;*Paths\instance + 1
;If *Paths\instance = 4
GetWindowText_(hwnd, @*Paths\classText, 256)
;If Asc(*Paths\classText)
;pos = FindString(*Paths\classText, ":")
pos = 1
If pos And AddElement(*Paths\Path())
;*Paths\Path() = Mid(*Paths\classText, pos + 2)
*Paths\Path() = *Paths\classText
Debug *Paths\Path() ; Never shows a path. :(
If FileSize(*Paths\Path()) <> - 2
DeleteElement(*Paths\Path())
EndIf
EndIf
ProcedureReturn 0
;EndIf
;EndIf
;EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Procedure enumChildren0(hwnd, *Paths.Paths)
If hwnd
GetClassName_(hwnd, @*Paths\classText, 256)
;If *Paths\classText = "CabinetWClass"
*Paths\instance = 0
EnumChildWindows_(hwnd, @enumChildren1(), *Paths)
;EndIf
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Define Paths.Paths
Paths\classText = Space(256)
EnumChildWindows_(0, @enumChildren0(), @Paths)
ForEach Paths\Path()
Debug Paths\Path()
Next
Re: Get list of all open folders (from Explorer windows)?
Posted: Sun May 26, 2024 10:51 am
by AZJIO
Re: Get list of all open folders (from Explorer windows)?
Posted: Sun May 26, 2024 11:07 am
by BarryG
Ah, so my Win 11 is newer than yours, which would explain it. Your examples don't work with the latest.

Thanks for trying!
Re: Get list of all open folders (from Explorer windows)?
Posted: Tue Jun 18, 2024 12:14 pm
by BarryG
Looks like this AutoHotkey code can do it for the current Windows 11 folder window... so does someone with better knowledge than I want to try converting it to PureBasic? I'll give you my nextborn child if you do.
Link ->
https://www.autohotkey.com/boards/viewt ... 3&t=109907