cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Quickest way to check if a folder and subfolders are empty?

Quickest way to check if a folder and subfolders are empty?

James_T
Helpful | Level 6

I only want the Dropbox Embedder to show if the specified folder actually have any files in it.

What is the best way to figure out if a folder (or subfolder) has any files?

At first I thought about "list_folder" and loop though the result to see if theres any file. But list_folder only returns 1 directory, and apparently need to use "continue" to get anything more? That's a bunch of queries!

The "Search" endpoint was my next thought, but I'm not sure how to search only for files?

Anyone have any suggestions?

3 Replies 3

Greg-DB
Dropbox Staff

While it may require more than one API call, using the /2/files/list_folder[/continue] endpoints (or corresponding native methods in the SDKs) is the best way to check if a particular folder is empty or not. The exact number of entries per page and total number of pages is not guaranteed and may vary by folder/account, so you would need to call back to /continue until 'has_more' is returned as false. I'll also pass this along as a feature request for a simpler way to check that, but I can't promise if or when that might be implemented.

James_T
Helpful | Level 6

Thanks for your reply.

The folder I tested list_folder with, contains only 4 directories. The API call only returned 1 folder (+ the root folder). Is that normal behavior?

It thought it would only require the continue call if there were lots of folder/files?

Greg-DB
Dropbox Staff

The number of entries you get back per page is not guaranteed, and it may require multiples calls even if there is not a large number of entries. You'll need to implement both list_folder and list_folder/continue and always call back for more entries until has_more is false in order to get the full listing.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    James_T Helpful | Level 6
What do Dropbox user levels mean?