Android Code Snippet ListFilesOnly - without directories

SubName: ListFilesOnly

Description: it is similar to File.ListFiles(Dir As String) but returns only file names, excluding directories.

B4X:
Public Sub ListFilesOnly(Dir As String) As List
    Dim lstDir, lstRes As List
    lstRes.Initialize
    
    If File.Exists(Dir, "") Then

        lstDir = File.ListFiles(Dir)
      
        Dim FileName As String
      
        For i = 0 To lstDir.Size - 1
            FileName = lstDir.Get(i)
            If Not(File.IsDirectory(Dir, FileName)) Then
                lstRes.Add(FileName)
            End If
        Next
      
    End If
  
    Return lstRes

End Sub

Tags: File, Files, Directory, Directories, Folder, Folders
 
Top