filename and subfolder/filename in listbox

I use this code right now:

SkabelonerListbox.DeleteAllRows

Dim f As FolderItem
f = SelectFolder

Dim filecount As Integer = f.Count
For i As Integer = 1 To filecount
  
  If f.Directory Then
    SkabelonerListbox.AddRow(f.item(i).name)
  Else
    MsgBox("Du har ikke valgt et bibliotek")
  End if
Next

Then I get filenames i the selected folder and only sufolders in the folder.
If I wan’t the subfolder/filename shown instead of only subfolder, how to do then?

from my head

SkabelonerListbox.AddRow(f.item(i).NativePath)

No, that’s not it, it only show the whole path to the file, not gives me any subfolder/filename.xxx

the code you have is a good start… it needs to be recursive…
and the place where you have msgbox is where the “files” will be shown

search this forum for “recursive” I’m sure you will find an example

Now I have this:

SkabelonerListbox.DeleteAllRows

Dim f As FolderItem
f = SelectFolder

Dim filecount As Integer = f.Count
For i As Integer = 1 To filecount
  
  If f.Directory Then
    if Right(f.item(i).name , 3)=".ft" or Right(f.item(i).name , 4)=".htm" then
      SkabelonerListbox.AddRow(f.item(i).name)
    End if
  Else
    ListFiles (f.absolutepath)
  End if
Next

And a Sub rutine:

if theFolder<>nil then
  if theFolder.Directory then
    for i as Integer=1 to theFolder.Count
      if theFolder.Item(i).Directory then
        ListFiles(theFolder.Item(i))
      else
        listbox3.addrow theFolder.Item(i).name
      end if
    next
  end if
end if

But that just give me this error:
Window1.TilføjButton.Action, line 15
Parameter “theFolder” expects class FolderItem, but this is type String.
End if

Where is line 15 ?

Did you follow Dave advice ? (searching for Recursion in this forum ?)

Edit: link for recursion @ wikipedie, below.

https://en.wikipedia.org/wiki/Recursion#In_computer_science

SkabelonerListbox.AddRow(f.Name + "/" + f.item(i).Name)

can give you a string subfolder/filename

@Emile Schwarz
Line 15 is:

ListFiles (f.absolutepath)

It is the line that parses the foldername to the sub rutine that should do the recursion…

ListFiles (f.absolutepath)

should probably be

ListFiles (f)

His code appears to be recursive.

I was awaiting a recursive Method. I do not noticed it; I’d better change my glasses.

The method header was missing.

Where is the command to display the line numbers ?
Xojo 2018r2.

I searched for nearly 10 minutes and I do not found it.

the button with a dash # on it in the method editor toolbar

Thank you Jean-Yves. I searched in the help and failed. And with your advice… I searched too and found this time (after a bunch of seconds…).

Did you read that Tue (and other readers) ?

You can set the lines numbers before copying the code (to paste it in the forum and be able to refer to a line #).

doesn’t work !

No it works, and I did like this:

[code]SkabelonerListbox.DeleteAllRows

Dim theFolder As New FolderItem
theFolder = Selectfolder

If theFolder Is Nil Then
Return
End If

Dim count As Integer = theFolder.Count
For i As Integer = 1 to count
Dim f As FolderItem = theFolder.Item(i)
If f <> Nil Then
If f.Directory = false then
If Right(f.Name , 3)=".ft" or Right(f.Name , 4)=".htm" then
SkabelonerListbox.AddRow(f.Name)
End if
else
ListFiles(f)
End if
End If
Next[/code]

and then I have this ListFiles under methods:

Dim count As Integer = theFolder.Count For i As Integer = 1 to count Dim f As FolderItem = theFolder.Item(i) If f <> Nil Then if f.Directory = false then If Right(f.Name , 3)=".ft" or Right(f.Name , 4)=".htm" then SkabelonerListbox.AddRow(f.Parent.Name + "/" + f.Name) End if else ListFiles(f) end End If Next

Thank you everybody for helping me out here