We start with a few DIMs for needed Variables
and a main sub from this tutorial
You can enable the LOG-outputs if you want to see more
The point is that we are using two global variables (LISTs) which holds all Folders and Files.
The sub will put all folders to list ffolders and al files to list ffiles and call itself recursive
But first we need to Initialize the lists and then we can read the Directory-Listing(s)
B4X:
sub Globals
Dim ffiles,ffolders As List
Dim root As String
End Sub
B4X:
Sub ReadDir(folder As String, recursive As Boolean)
'Log("ReadDir("&folder&")")
Dim lst As List = File.ListFiles(folder)
For i = 0 To lst.Size - 1
If File.IsDirectory(folder,lst.Get(i)) Then
Dim v As String
v = folder&"/"&lst.Get(i)
'Log("v="&v)
ffolders.Add(v.SubString(root.Length+1))
If recursive Then
ReadDir(v,recursive)
End If
Else
ffiles.Add(folder&"/"&lst.Get(i))
End If
Next
'Log(ffolders.Size&" Ordner / "&ffiles.Size&" Dateien")
End Sub
The point is that we are using two global variables (LISTs) which holds all Folders and Files.
The sub will put all folders to list ffolders and al files to list ffiles and call itself recursive
But first we need to Initialize the lists and then we can read the Directory-Listing(s)
B4X:
Sub Activity_Create(FirstTime As Boolean)
ffiles.Initialize
ffolders.Initialize
root = File.DirRootExternal
ReadDir(root,True)
Log(ffolders.Size&" folder / "&ffiles.Size&" files")
End sub
Last edited: