Recursive Function behaving weird!?

Hi there!

I want to scan a folder and its subfolders for files and add them to the list.
The files of the main folder are added nicely, then the function calls itself (tested it) with the path for the subfolder (its correct, i also tested it), but nothing happens. There is no error but it just doesnt work. Any Ideas?

Function LoadFiles with parameters “path as String”:

Dim testFolder As New FolderItem(path,FolderItem.PathTypeAbsolute)
  If testFolder Is Nil Then
    Return
  End If
  
  Dim count As Integer = testFolder.Count
  For i As Integer = 1 to count
    Dim f As FolderItem = testFolder.Item(i)
    If f <> Nil Then
      if f.Directory = false then
        lstTableFiles.AddRow(f.Name)
      else
        LoadFiles(Str(path+f.Name))
      end
    End If
  Next

Try LoadFiles( f.AbsolutePath ) instead.

Okay, that did it, thank you very much. I still dont really get why it didnt work the other way…

Path doesn’t have the required trailing “:” (Mac), “” (Win), or “/” (Linux).

Even better would be to pass f (the folderitem) itself.

@Simon Müller
When I try, I get the error message:
Parameter “theFolder” expects class FolderItem, but this is type String.
ListFiles(f.Nativepath)

How did you do the trick?

Its a bit hard to debug your code if you don’t post a copy of it :slight_smile:

@Tue Sandbæk He is passing the path and creating a folder each time. In your other thread, you seem to be passing the folderitem itself. I suggested a fix for that.

AbsolutePath is deprecated. Check the documentation.

Hello @Tim Hare, I’ve got it working now!
I’ll describe it in the other thread:
link text