Android Question File.IsDirectory fails

ilan

Expert
Licensed User
Longtime User
hi

i am trying to check if a file i get from File.ListFiles(...) is a directory but i am getting a crash.

i am targeting sdk26 and i request the permission to _WRITE_EXTERNAL_STORAGE so that should not be the problem.

this is my code:

B4X:
Dim list1  As List
list1.Initialize
list1 = File.ListFiles(File.DirRootExternal)

Log("size: " & list1.Size)

For x = list1.Size-1 To 0 Step -1
    If File.IsDirectory(File.DirRootExternal, "/" & list1.Get(x)) = False  Then
        list1.RemoveAt(x)
    End If
Next

i also tried to remove "/" before the file name but did not worked.

this is the crash log:


any idea what is wrong?

i also need to mention that some files are written in hebrew, could that be the reason?

thanx, ilan
 

ilan

Expert
Licensed User
Longtime User
ok, ok, ok, i got it



i just create now a second list and copy all directories to it and use it instead of list1

B4X:
Dim list1, list2 As List
list1.Initialize
list2.Initialize

list1 = File.ListFiles(File.DirRootExternal)

For x = 0 To list1.Size-1
    If File.IsDirectory(File.DirRootExternal, "/" & list1.Get(x)) Then
        list2.Add(list1.Get(x))
    End If
Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…