How to properly update file num for DirectoryContentsList?

I’m using DirectoryContentsList to read local files in a folder, and I need to save the total file number for showing to user, but I found scanning files requires time, so the final number won’t come out quick.

Any suggestions on how/where to put the file num update function below? Do I have to constantly check if it is still scanning in processBlock? Sounds not efficient enough…

int getNumFiles () const noexcept
Returns the number of files currently available in the list.