We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Bin2
6 years agoNew member | Level 2
Searching for a specific file type
Hi there,
I'll ask for some patience and forgiveness in advance. Im about 2 weeks in to Python devleopment, so Im likely missing some obvious approaches - please dont assume a lot of knowledge on ...
Bin2
6 years agoNew member | Level 2
I believe I have solved my own problem - incase anyone else needs it. Its not pretty - but it works.
spot=[]
holder=[]
holder=dbx.files_list_folder('/Test Folder')
print(holder)
for files in holder.entries:
spot.append(files.path_lower)
print(spot)
pattern = '*.jpg'
matching = fnmatch.filter(spot, pattern)
print(matching)
['/test folder/az-car-rental.jpg', '/test folder/il-car-rental.jpg', '/test folder/car-rental-invoice.jpg', '/test folder/dinner-receipt.jpg', '/test folder/lunch-receipt.jpg', '/test folder/meal-receipt.jpg', '/test folder/meetup-dinner.jpg', '/test folder/team-offsite-lunch.jpg', '/test folder/training-airfare.jpg', '/test folder/training-hotel-invoice.jpg', '/test folder/travel-meal.jpg']- Greg-DB6 years ago
Dropbox Community Moderator
I'm glad to hear you already got this working. You have the right idea in that you can call files_list_folder to list the contents of a folder, and then check the Metadata.path_lower (or Metadata.name) for the returned entries to see if the file extension is one you're interested in.
Note though that you should also implement files_list_folder_continue to make sure you can receive all of the entries. Check out the files_list_folder documentation for more information.
Also, one alternative for your file extension check may be to use the 'endswith' method like this:
files.path_lower.endswith(".jpg")
About Discuss Dropbox Developer & API
Make connections with 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!