cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
From Dropbox Dash and Dropbox AI to seamless integrations with tools like Gmail, learn how Dropbox makes your day more efficient and easier, and how sci-fi is becoming reality 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: 
1
Ask
2
Comments

Re: Retrieve with a File limit and File count

Re: Retrieve with a File limit and File count

ipico
Explorer | Level 3
Go to solution

I'm looking for a way to get the count of entries from this python api call:

e=dbx.files_list_folder('/myfolder').entries

None of the following work:

>>> print(e.count)
<built-in method count of list object at 0x107dcd098>

>>> print(e.size)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'size'

>>> print(e.list)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'list'

I can iterate and increment in a for loop but would prefer to use an existing method:

i=0
for entry in dbx.files_list_folder('/myfolder').entries:
    i=i+1

print(i)

Is there a way to get the count of the files returned without actually iterating through the list? 

1 Accepted Solution

Accepted Solutions

Re: Retrieve with a File limit and File count

Greg-DB
Dropbox Staff
Go to solution

The ListFolderResult.entries returned by files_list_folder is a 'list' so you can use Python's 'len' function to get its length, like this:

print(len(dbx.files_list_folder('/myfolder').entries))

Please note though that you're not guaranteed to get all of the files/folders in a particular folder back in a single call to files_list_folder. If ListFolderResult.has_more is 'true' you need to call back to files_list_folder_continue for more entries. Check out the files_list_folder documentation for more information.

View solution in original post

1 Reply 1

Re: Retrieve with a File limit and File count

Greg-DB
Dropbox Staff
Go to solution

The ListFolderResult.entries returned by files_list_folder is a 'list' so you can use Python's 'len' function to get its length, like this:

print(len(dbx.files_list_folder('/myfolder').entries))

Please note though that you're not guaranteed to get all of the files/folders in a particular folder back in a single call to files_list_folder. If ListFolderResult.has_more is 'true' you need to call back to files_list_folder_continue for more entries. Check out the files_list_folder documentation for more information.

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?
Need more support?