Recursive list of folders

Hi guys,
has someone already managed how to fill a hierarchical list or a listbox with files in a root folder ?
Like what you get in development for the Ressources folder ?

I want to develop it again, or better to ask 4D to add a search box based on file name !!!
With databases with hudge buttons and icons, this is very time consuming to seek thru…

But whatever will do 4D, this is also a recurrent need to have a recursive method to fill a listbox with folders and files.

[]33422111;“Hierarchical list…”[/]

Thanks for your advises and your code…

Old school, see code in 4DPop Image Buddy
New way, use the File and Folder commands

Ouah Vincent, this help me a lot :slight_smile:
But you got the price of the fastest answer !!!

To be honest, 4D pop Image Buddy is a good thing to have a look in, thanks.

To be fully honest, a big thanks, as this 4D pop is doing exactly what I need !
Mmmmf, some little things to improve, but it really helps and I had it on my fingers daily.


Il y aça>, aussi (fait dans un moment de frustration d’être englué en version avant file/folder.)

I was looking for one yesterday. “Folder” gives a lot of options, but I could not see how to keep Packages out of the list when using its recursion option. So this… but just for Folders so far.

<code 4D>
// Call the method
$folder:=Select folder(“Select the Source folder”;1001)
If (OK=1)
$folder:=Convert path system to POSIX($folder)
Docs:=New collection
Docs:=FolderList_Rx ($folder;0;Docs)
End if

// ----------------------------------------------------
// Method: FolderList_Rx
// INPUT1: Text - folder pathname
// INPUT2: Longint - folder’s level (root=0)
// OUTPUT: Collection - of folders’ info
// ----------------------------------------------------

$space:=" "*($level-1)

$folderList:=$folder.folders(fk ignore invisible)
$folderList:=$folderList.orderBy(“name desc”)

For each ($obj;$folderList)

If (Not($obj.isPackage))  // eliminate candidates here
	$out:=FolderList_Rx ($obj.path;$level;$out)
	If ($obj.isFolder)
		$pType:=$obj.extension  // 
	End if 
	$cGet:=New object("nameShort";$;"name";$space+$;"level";$level;"copy";False;"type";$pType)
End if 

End for each


</code 4D>

I use methods published in Planète 4D years ago, modified, and I am adapting them to new commands : File, Folder, collections…
Their advantage : analyze folders when you click to deploy.
It may be also an inconvenient !


but I could not see how to keep Packages out of the list when using
its recursion option

There is a property folder.isPackage…

Yes, I was thinking of something like Folders.folders(fk ignore packages), but since there will always be an unexpected filter requirement, having a general routine is just as well.

<code 4D>
$folderList:=$folder.folders(fk ignore invisible).query(“isPackage = false”)
</code 4D>

There’s always something…

$collection.query() will include the folders that are inside of older versions of Apple’s Pages documents. It will not include the Pages document itself.
Newer Apple’s Pages documents do not get included in the collection.

$folder.folders() will include the old Pages docs.
isPackage = true
isFolder = true
isFile = false

Right-click an old Pages doc and you see “Show Package Contents…” in the menu.
Right-click an new Pages doc and you will not.

If Packages are to be omitted, it seems their contents would be omitted too. Should this ba a bug report?


I see now the problem is here:
$Folders:=$folder.folders(fk ignore invisible+fk recursive) // the inside folders are present
$Folders:=$Folders.query(“isPackage = false”) // only the package gets filtered

I should have added that the original statement was:
$Folders:=$folder.folders(fk ignore invisible+fk recursive).query(“isPackage = false”)


Ok, thanks to you all.
The better trick was to look on 4D pop Image Buddy…

After 12 hours, I created a new 4D pop : “4DPop Resources
Based on Images Buddy but, able to display all kinds of files.

Then a hudge re-layout to better follow the original 4D Resources
tool, plenty of bug’s corrections, a global search, code rewriting,
right click menus revisited…

**** “4DPop Resources Buddy.4dbase” ****
VERSION 1.1.00, on 17th January 2020
Rewriting of this amazing good component : “4DPop Image Buddy.4dbase”.

The goal was to

  • be able to have a global searchbox, displaying all folders
    containing files with the pattern in the name.
  • extends to “Resources Buddy”, like done with 4D Resources tool.

• Display bug for the picts in the listbox. Corrected just adding
horizontal and vertical grid !
• Splitters remplaced with real 4D splitters.
• Layout revisited like 4D tool, with a preview added.
• Menus on right click all revisited, adding more “copy” than just
the content : absolute path, relative path, relative path with “/”,
and file name.
• Add a global searchbox : really powerfull !!!
• Works for all kinds of files in the resource folder, not only
• Add this version text

Made by Olivier Grimbert, on January 17, 2020
Based on “4DPop Image Buddy.4dbase”

My question is :
How, and where, to publish the source and the compiled component ?
On my site with a link here ?
How 4D is managing that the 4D Pop sources are now available, and how to deal with forks ?
In my case it is different as I created a new component with a new name.


[]33435820;“The main window”[/]

And the must : you type in the global searchbox, and you get folders with files which name contents fitted.

[]33435849;“Looking for file’names containing ‘email’…”[/]

: Olivier GRIMBERT

How, and where, to publish the source and the compiled component ?
On my site with a link here ?

In your site, you can, but if you want to do this here, you have to publish it in “Sharing Code” forum.
You also can send it to VDL :wink:


I recommend to publish on GitHub
Simple, free, visible for all.
Then give me the link to add into the 4DPop project.

I fell in trouble, looking at this in 4D pop Image buddy :

mnu_RELEASE_MENU ($Mnu_main)

I knew that a sub menu, once attached to its upper level, has to be suppressed with RELEASE MENU.

But, then, when you release the root menu, I was guessing all menus are released, root and all subs.

So, this method let me think that it is not the case ?

This is important to be sure in all my databases I have a point of making memory leaks…

Thanks for your answer.

Here is the github link to get the new 4D pop, it is a zip with sources and compiled in it.

Enjoy !