Android Question Looking for fast way to identify Folders only

GuyBooth

Active Member
Licensed User
Longtime User
I have a ListView where I list all the subfolders in a folder. First I create a list, and before loading them into the ListView I test to determine whether each entry is a Folder rather than a file. In most cases this works fine, but occasionally I hit a folder that has several thousand files in it. When this happens, the testing takes a long long time, because it has to test all the entries!
I can limit the total number of entries searched, as shown here, but it is possible that no folders would show up at all.

B4X:
lstAllArray = File.ListFiles(edtPath.text)
' Sort the list
lstAllArray.Sort(True)
' Create a "real" lists. Limit the number of items counted to 75
' to avoid long periods with no apparent activity.
For i = 0 To Min(lstAllArray.Size - 1, 75)
     ' Create a proper list of just Folders
     If File.IsDirectory("", edtPath.text & "/" & lstAllArray.Get(i)) Then
            lstFolders.Add(lstAllArray.Get(i))
     End If       
Next

Would appreciate it if anyone can show me a way to list just the folders quickly, even in a folder that contains hundreds of files.
 

DonManfred

Expert
Licensed User
Longtime User
Use a thread to determine the folders if your code running to long
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Use a thread to determine the folders if your code running to long
Perhaps I need to clarify ...
This isn't a background task. The search starts when the user clicks on a button. He/she will be sitting waiting for the result.
Or have I misinterpreted your suggestion?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
No.
There is no faster way... Checking a folder which contains a lot of files DO NEED some time

If you can strip it down a bit then maybe it´s faster.
Try to not use the check; instead only use folders without extension and only files WITH extension.
You then can check just the filenames coming from
B4X:
File.ListFiles(edtPath.text)
instead of the need to look into the folder
B4X:
 If File.IsDirectory(
 
Upvote 0
Top