filename and subfolder/filename in listbox

  1. 9 weeks ago

    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?

    No it works, and I did like this:

    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

    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

  2. Axel S

    is not verified Sep 14 Europe (Germany, Erfurt)

    from my head

    SkabelonerListbox.AddRow(f.item(i).NativePath)
  3. 8 weeks ago

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

  4. Dave S

    Sep 14 San Diego, California USA

    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

  5. 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

  6. Emile S

    Sep 15 Europe (France, Strasbourg)
    Edited 8 weeks ago

    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

  7. Axel S

    is not verified Sep 15 Europe (Germany, Erfurt)
    SkabelonerListbox.AddRow(f.Name + "/" + f.item(i).Name)

    can give you a string subfolder/filename

  8. Edited 8 weeks ago

    @Emile S
    Line 15 is:

    ListFiles (f.absolutepath)

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

  9. Tim H

    Sep 15 Pre-Release Testers Portland, OR USA
    ListFiles (f.absolutepath)

    should probably be

    ListFiles (f)
  10. Tim H

    Sep 15 Pre-Release Testers Portland, OR USA

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

    His code appears to be recursive.

  11. Emile S

    Sep 16 Europe (France, Strasbourg)
    Edited 8 weeks ago

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

    The method header was missing.

  12. Emile S

    Sep 16 Europe (France, Strasbourg)

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

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

  13. Jean-Yves P

    Sep 16 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

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

  14. Emile S

    Sep 16 Europe (France, Strasbourg)

    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 #).

  15. Jean-Yves P

    Sep 16 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    @Emile S 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 !

  16. Tue S

    Sep 16 Answer

    No it works, and I did like this:

    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

    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

or Sign Up to reply!