Android Question List files of Main.rp.GetSafeDirDefaultExternal directory

DanteS

Member
Licensed User
Longtime User
Hi guys

To read the text of a .txt file in DefaultExternal and to read the list of all file in the directory I use the code shown below.

Why the File.ReadString instruction works fine and the File.ListFiles seams to read an empty list?

code:
    Dim x As String
    Dim ld As List
    ld.Initialize
           
    x = File.ReadString(Main.rp.GetSafeDirDefaultExternal(""), archi)
    ld=File.ListFiles(Main.rp.GetSafeDirDefaultExternal(""))

Note: archi is a variable containing the name of the file to be read
 
Last edited:

walt61

Active Member
Licensed User
Longtime User
It works here - B4A 13.00, JDK 19, Android 12 (Xiaomi MIUI 14.0.6):
B4X:
    Dim rp As RuntimePermissions
    Log("Dir: " & rp.GetSafeDirDefaultExternal("")) ' Dir: /storage/emulated/0/Android/data/b4a.example/files
    File.WriteString(rp.GetSafeDirDefaultExternal(""), "test.txt", "Test")
    File.WriteString(rp.GetSafeDirDefaultExternal(""), "test2.txt", "Test2")
    File.WriteString(rp.GetSafeDirDefaultExternal(""), "test3.txt", "Test3")
    Log("Contents: " & File.ReadString(rp.GetSafeDirDefaultExternal(""), "test.txt")) ' Contents: Test
    Log("List: " & File.ListFiles(rp.GetSafeDirDefaultExternal(""))) ' List: (ArrayList) [test.txt, test2.txt, test3.txt]
 
Upvote 0
Top