1

I'm using the following code to get the total number of files present at root level in a folder for Dropbox:

public int getFilesCount(@NonNull final String inPath) throws DbxException {
    Log.i(LOGGER, "Getting files count for: " + inPath);
    ListFolderResult result = mClient.files().listFolder(inPath);
    return result.getEntries().size();
}

This code works correctly!

But looks like this code first get the list of all files present under the folder and then gets the count. This takes a significant network time. Is there any faster way to just get the total number of files instead of iterating over the directory?

Using Dropbox version 3.0.3

Greg
  • 16,359
  • 2
  • 34
  • 44
DR93
  • 463
  • 6
  • 21

1 Answers1

3

There isn't a way to retrieve the file count without listing everything and counting unfortunately. We'll consider it a feature request.

Also, note that the listFolder interface is paginated, so you aren't guaranteed to get everything in a single call to listFolder. You may need to additionally call listFolderContinue. You can find more information in the listFolder documentation:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/files/DbxUserFilesRequests.html#listFolder-java.lang.String-

Greg
  • 16,359
  • 2
  • 34
  • 44