Android Question sFTP : How can I sort the Folders and Files by name?

Meuke

Member
Licensed User
Longtime User
I am using sFTP to get the folders and files from a given serverpath.
The strange thing is that the folders and files are listed in a random order.
Is there any way that the folders and the files can be sorted in alphanumeric order?
Below is the code that I am using to display the folders and files on an Android Tablet.
Can someone lead me in the right direction to solve this problem and make the correct changes to my code?
I am not an expert in this matter so any help would be helpfull.

B4X:
Sub sFTP1_ListCompleted (ServerPath As String, Success As Boolean, Folders() As SFtpEntry, Files() As SFtpEntry)
    strServerDir = ServerPath
    
    If Success = False Then
      
    Flag_Verbinding = False
    MsgboxAsync("No Connection", "NO CONNECTION")
    Activity.Finish
        
    Else
    Flag_Verbinding = True
        
        If strServerDir <> "/" Then
            lvServer.AddTwoLinesAndBitmap2(".."," UP",bmpFolderUp,"U$..")
    End If
        
    For i = 0 To Folders.Length - 1
    lvServer.AddTwoLinesAndBitmap2(Folders(i).Name,"",bmpFolder,"D$" & Folders(i).Name)
        Next
        
        For i = 0 To Files.Length - 1
    lvServer.AddTwoLinesAndBitmap2(Files(i).Name,NumberFormat((   (Round(Files(i).Size / 102.4)/10)    ),0,1) & " K           " & DateTime.Date(Files(i).Timestamp),bmpFile,"F$" & Files(i).Name & "$" & Files(i).Size)
    Next
            
    End If
End Sub
 

teddybear

Well-Known Member
Licensed User
Put names of Folders into a list, and sort the list. do the same for names for Files
B4X:
    Dim FNlst as List
    FNlst.Initialize
    For i = 0 To Folders.Length - 1
        FNlst.Add(Folders(i).Name)
    Next
    FNlst.Sort(True)
    For i = 0 To Folders.Length - 1
        lvServer.AddTwoLinesAndBitmap2(FNlst.Get(i),"",bmpFolder,"D$" & FNlst.Get(i))
    Next
 
Upvote 1

Meuke

Member
Licensed User
Longtime User
Put names of Folders into a list, and sort the list. do the same for names for Files
B4X:
    Dim FNlst as List
    FNlst.Initialize
    For i = 0 To Folders.Length - 1
        FNlst.Add(Folders(i).Name)
    Next
    FNlst.Sort(True)
    For i = 0 To Folders.Length - 1
        lvServer.AddTwoLinesAndBitmap2(FNlst.Get(i),"",bmpFolder,"D$" & FNlst.Get(i))
    Next
Hello,
Thanks for solving my problem with the code for sorting the filenames.
This was exactly what I was looking for. Now I can proceed with my project.
Kind regards,
Meuke
 
Upvote 0
Top