Fastest Way To Get FolderItem Names Into Array?

[quote=111827:@Tim Jones]FileListMBS++

Same here.[/quote]

Out of curiosity how is the speed (which might be able to be sped up more with pragmas) of the Xojo declare code compared compared to the MBS method?

The MBS method is cross platform while the Xojo declare above is Windows only.

Having said, that, they are on par speed-wise on Windows.

Got it! I had to retype parts of the call to the function since somehow a non-visible character crept into the name to intentionally sabotage my work.

Thanks for the help.

[quote=111842:@Tim Jones]The MBS method is cross platform while the Xojo declare above is Windows only.

Having said, that, they are on par speed-wise on Windows.[/quote]

Is speed an issue on OS X using the code in te above method? When I’ve had to deal with a lot of files it has always been on Windows, not OS X.

  • Karen

One thing I forgot to mention. Note the wildcard file name specifications…

You can substitute (or write a function where you can pass in) any valid file name wildcard string ,and have it only return files with matching names… I typically use that when looking for files with a specific extension.

Of course on other OSes besides windows , you would have to check the filename yourself in Xojo code, but you would anyway unless they have equivalent declares.

The MBS function is much faster on OS X than the method above. I often have to deal with millions of files in film processing (an average film = 120 minutes of DPX frames at 29.97 frames per second = 12,947,040 files…)

Thank you very much for this. The routines I had from Aaron Ballman turn up their toes under Xojo ( RB is fine ), so this has saved the day.

Sorry to open an older thread again. Could anyone show me how I can use this function to list all files and folders in a directory, recursively?



Thanks Michel. I saw this but I can’t figure out how to map the regular folderitem to the ItemNames function.

The very simple example on that page precisely picks itemName from item to put it into a ListBox. Can you explain more clearly what you are trying to achieve ?

When I have this:

Dim dlg as New SelectFolderDialog Dim f as FolderItem Dim itemIdx as Integer Dim dirCount as Integer Dim item as FolderItem dlg.InitialDirectory=SpecialFolder.Documents f=dlg.ShowModal() If f <> Nil then dirCount = f.Count For itemIdx = 1 to dirCount item = f.Item(itemIdx) If item <> nil Then DataList.addrow End If Next end if

I don’t know how to call the ItemNames function.
I also don’t see how to use the boolean ReturnFileNames.

If you want it recursively, it’s easier to pass it on to a Method so it can call itself when it finds a sub folder.


  Dim dlg As New SelectFolderDialog
  Dim f As FolderItem = dlg.ShowModal()
  If f <> Nil Then
  End If


Sub ListFiles(theFolder As FolderItem)
  Dim f As FolderItem
  If theFolder <> Nil And theFolder.Directory Then
    Dim items As Integer = theFolder.Count
    For i As Integer = 1 To items
      f = theFolder.Item(i)
      If f.Directory Then
  End If
End Sub

Hi Marco, my first and main problem is that I don’t see how to use Karen’s ItemNames function.

Check out the extends keyword in the docs. This adds the itemsNames function TO the folderitem. You call it just like a method of the folderitem.

dim myResult(-1) as string = myFolderitem.itemNames

Ah :slight_smile:
See the first line:

Function ItemNames(extends f as folderItem, ReturnFileNames as boolean = true, ReturnFolderNames as boolean = true) As String()

Note where it says “extends f as folderItem”.
In your project, add a module. Then inside this module add the Function.
Then you can do something like:

Dim someFolderitem As FolderItem
Dim someArray() As String
someArray = f.ItemNames(true, true)

Marco, that was what I was looking for indeed.
I don’t have the impression it is so much faster, so I think I’m still doing something wrong.
So I’ll investigate this a bit more this afternoon.
This is anyhow already a step forward.


The digging of the files itself should be pretty fast.
Adding the items to your ListBox is often the part that is slowing things down.

that might be the problem indeed…
or the fact I’m also writing all do a db (within a transaction of course)