Android Question File.ListFiles

Indy

Active Member
Licensed User
Longtime User
Hi Folks,

I am really puzzled regarding the File.ListFiles method. For some unknow reason my code isn't working as intended. Having done the neccessary object initialisation, I perform the following command to check for an empty folder..

B4X:
list1 = File.ListFiles(Main.SavePath)

I then evaluate the return as follows..

B4X:
If list1.Size>0 Then
.....
.....
.....
End If

However, the code fails to detect the zero count and still executes the code within the If statement, which as a consequence cause an index out of range error (0 reference). I did a log(list1.Size) and even that counts 0, so why does the code still get executed?

Would appreciate any pointers because I'm out of ideas.

Thank you.
 

Mahares

Expert
Licensed User
Longtime User
This code works: Note that all variables are in the same main module.

B4X:
Dim List1 As List
Dim Savepath As String=File.DirRootExternal & "/Playlists"  'in Gloabls of main module


B4X:
List1.Initialize    'in Activity_create
List1 = File.ListFiles(Savepath)
If List1.Size > 0 Then
    Log("not empty")
Else
   Log("empty")
End If
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Hi Mahares

Thanks for the example. I found what the issue was, which had nothing to do with the "Count". It was a label that I was updating that had nothing in it which caused the problem. I had to comment out almost the entire sub to find this bug. Got it fixed and all is working as expected. Thanks for your help.
 
Upvote 0
Top