Browse folders recursively

Hi,
Does anyone have a routine for iterating through folders recursively?
I am looking to browse the files in each folder (and sub-folders) present in ‘/Users/UserName’ in order to display files whose size exceeds 100MB (for example).
Thanks,

You can do that with folderitem class of course.

Or check alternatives like FileListMBS in MBS Xojo Plugins, which can be much faster.

thanks, i’ll take a look.

Make sure you’re using For Each with the folderitem.children iterator. It’s significantly faster than ChildAt

Isn’t the StackOverflow danger valid any longer?

10 years ago, simple recursion (method calling itself) had to be avoided because the stack would overflow if the folders went too deep.
It has been several years that the answers for this question won’t mention this issue and lead to think it’s now OK to use methods recursion. Something has changed since then?

Your app has several megabytes of stack space.
All the objects are on the heap, so in Xojo you can usually do thousands of recursions without problems.

Thanks.
So this has indeed changed, since ten years ago, a recursion of about 10 sub levels would overflow the stack.

Hi @Christian_Schmitz ,

In the “Util/File List Recursive” example (Method LoadFolderMBS), why when I want to replace the (deprecated) command “if g.Directory(i) then…” with
“if g.IsFolder(i) then …” (or just if g.IsFolder), I get the message:

Type “FileListMBS” has no member named “IsFolder” ???

(but it works under LoadFolderRB)
Thanks

I think you confuse methods in the FolderItem class with methods in FileListMBS class.

1 Like

@Christian_Schmitz

Thank you for your answer. Yes I understand.
Another thing, the FileListMBS class is very fast but it does not seem to support the icons of the elements (files/folders) displayed, unlike the classic “RB” class. Is there a solution to display the icons?

Listbox1.RowImageAt(Me.LastAddedRowIndex) = g.IconMBS(16)
“This method extends class FolderItem, but the base expression is class FileListMBS.”

For such a function, you would ask for the folder item for the entry.

The key thing of FileListMBS is to do things, where you can work on the files without using FolderItem.
e.g. Match files to a criteria and only get FolderItem for a few of them.

If you query FolderItem for each item, you can skip FileListMBS and do FolderItem directly.
The time advantage in FileListMBS is to not make FolderItem objects.