I Indy Active Member Licensed User Longtime User Sep 23, 2014 #1 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.. Code: list1 = File.ListFiles(Main.SavePath) I then evaluate the return as follows.. Code: 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.
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.. Code: list1 = File.ListFiles(Main.SavePath) I then evaluate the return as follows.. Code: 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.
M Mahares Expert Licensed User Longtime User Sep 23, 2014 #2 This code works: Note that all variables are in the same main module. Code: Dim List1 As List Dim Savepath As String=File.DirRootExternal & "/Playlists" 'in Gloabls of main module Code: List1.Initialize 'in Activity_create List1 = File.ListFiles(Savepath) If List1.Size > 0 Then Log("not empty") Else Log("empty") End If Upvote 0
This code works: Note that all variables are in the same main module. Code: Dim List1 As List Dim Savepath As String=File.DirRootExternal & "/Playlists" 'in Gloabls of main module Code: List1.Initialize 'in Activity_create List1 = File.ListFiles(Savepath) If List1.Size > 0 Then Log("not empty") Else Log("empty") End If
I Indy Active Member Licensed User Longtime User Sep 27, 2014 #3 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
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.