Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
pyraxic
8 years agoHelpful | Level 6
Dropbox API not returning all files
I am using Django and trying to get the list of all files. My dropbox contains 4149 files but it only returns 3998. Upon checking it seems that the most recent files uploaded to Dropbox isn't showing...
- 8 years ago
I tried running the code you posted and was able to reproduce the issue of it dropping the last page. Here's a fixed version:
dbx = dropbox.Dropbox(oauth_result.access_token) result = dbx.files_list_folder("", recursive=True) file_list = [] def process_entries(entries): for entry in entries: if isinstance(entry, dropbox.files.FileMetadata): file_list.append([entry.name]) process_entries(result.entries) while result.has_more: result = dbx.files_list_folder_continue(result.cursor) process_entries(result.entries) print(len(file_list))
Greg-DB
Dropbox Community Moderator
8 years agoThanks! I just took another look at your code, and it looks like it actually won't process the last page of results. That is, the last call to `files_list_folder_continue` will cause `m2.has_more` to be `False`, which will terminate your `while` loop before that final `m2.entries` is processed. You'll just need to restructure the code to avoid that. (E.g., only put `files_list_folder_continue` at the top of `while` loop, or something to that effect.)
pyraxic
8 years agoHelpful | Level 6
Hi Greg,
files_list_folders_continue() is already outside of the while loop.
m2 = dbx.files_list_folder_continue(cur)
while m2.has_more == True:
for i in m2.entries:
if isinstance(i, dropbox.files.FileMetadata):
flist.append(i.name)
cur = m2.cursor
m2 = dbx.files_list_folder_continue(cur)- Greg-DB8 years ago
Dropbox Community Moderator
I'm referring to the second call to files_list_folder_continue at the end of the while loop.- pyraxic8 years agoHelpful | Level 6
Even putting it outside of while loop didn't make any difference.
m2 = dbx.files_list_folder_continue(cur) while m2.has_more == True: for i in m2.entries: if isinstance(i, dropbox.files.FileMetadata): flist.append(i.name) cur = m2.cursor m2 = dbx.files_list_folder_continue(cur) return render(request, 'accounts/dropbox.html', {'flist': flist}) - pyraxic8 years agoHelpful | Level 6
I even changed that to outside of loop but same results. It doesn't seem to be getting to the while loop at all.
- Greg-DB8 years ago
Dropbox Community Moderator
I tried running the code you posted and was able to reproduce the issue of it dropping the last page. Here's a fixed version:
dbx = dropbox.Dropbox(oauth_result.access_token) result = dbx.files_list_folder("", recursive=True) file_list = [] def process_entries(entries): for entry in entries: if isinstance(entry, dropbox.files.FileMetadata): file_list.append([entry.name]) process_entries(result.entries) while result.has_more: result = dbx.files_list_folder_continue(result.cursor) process_entries(result.entries) print(len(file_list))
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!