I have a String Array that I am creating as follows:
B4X:
Dim booknames() As String = Array As String("text_creative_arts.epub", _
"text_english_reader.epub", _
"text_Life_Orientation.epub", _
"text_mathematics.epub")
I wish to now create this Array "on-the-fly" by reading the files within the folder.
I can create a List of files, as follows:
B4X:
Dim ImageList As List
Dim ImageCount As Int
ImageList = File.ListFiles("/storage/emulated/0/books/Text/")
ImageCount = ImageList.Size
Log("File List = " & ImageList)
Log("File Count = " & ImageCount)
write a small sub which get the list as parameter and which will create the right array for you with the content of the list and return the newly created array
Dim L As List = File.ListFiles(File.DirRootExternal)
Dim Arr(L.Size) As String = AsJO(L).RunMethod("toArray",Null)
For i = 0 To Arr.Length - 1
Log(Arr(i))
Next
Private Sub AsJO(Jo As JavaObject) As JavaObject
Return Jo
End Sub
I'm not sure that it will give any noticeable performance gains over doing it yourself in a loop, or using the List directly , but it's there as an option.