You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
muratowski
2 years agoHelpful | Level 5
Unable to list files in shared Dropbox folder using Python and the Dropbox API
I am trying to use Python and the Dropbox API to list the files in a shared Dropbox folder. Here is my source code: """ import dropbox import os # Replace "ACCESS_TOKEN" with your Dropbox a...
- 2 years ago
Ok I changed my codebase a little bit and now it works perfectly!
Thank your for your efforts.
Greg-DB
2 years agoDropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/75725830/unable-to-list-files-in-shared-dropbox-folder-using-python-and-the-dropbox-api ]
Which line is resulting in that error? It looks like that error is probably referring to a local filesystem operation, not a Dropbox API call.
Also, while it's probably not related to this particular error, there are some other things to note for the Dropbox API methods:
- You've implemented files_list_folder but not files_list_folder_continue. You're not guaranteed to get all of the entries returned in one call to files_list_folder so make sure you've implemented files_list_folder_continue as well. Check out the linked documentation for more information.
- You're relying on 'entries[-1]' to find a folder entry, but note that the position of specific entries in any particular page of results in not guaranteed.
- muratowski2 years agoHelpful | Level 5
Hi,
I got an error on line 27 of my code:
---> 27 directories = os.listdir(folder_path)
Do you have any alternative code suggestions? Also, if possible, could you show me where to insert the code changes in my base?
FYI I run the script in Google Colab. Thanks!"
- Greg-DB2 years agoDropbox Staff
The os.listdir method is a Python method for listing the contents of a particular folder on the local filesystem at the specific path. It accesses the files and folders on the device and a FileNotFoundError error from it would indicate that there is nothing at the local path you specified, in this case using the value in the folder_path variable. The method does not call the Dropbox API and is not made by Dropbox though, so Dropbox can't offer support for that in particular.
I see you are getting the folder_path value from the files_list_folder results. That would only work with os.listdir if the path to the relevant folder on your local machine happened to match the path to it inside your Dropbox account.
I don't have full context on your project or the requirements and constraints you're working under of course, so I can't tell you exactly what code you should write. It may be helpful to step through with a debugger to see what each line is doing and update your code accordingly.
It may also be worth mentioning that if you ultimately want to move or rename files or folders in Dropbox, you can do so directly using the Dropbox API (whether or not you have your Dropbox folder synced to your computer locally), without interacting with the local filesystem. To move or rename a file or folder using the Dropbox API via the Dropbox Python SDK, you would use files_move_v2. And as noted earlier, you can use files_list_folder and files_list_folder_continue to list the contents of a folder (even without a shared link, if the content is in your connected Dropbox account). You may also want to check out the Getting Started and File Access guides.
- muratowski2 years agoHelpful | Level 5
Thank you for the explanation.
I would like a Python script that can rename all the subdirectories within a specific main directory in my Dropbox account. The subdirectory names are currently in the format 'dd.mm.yyyy', but I would like them to be changed to the format 'yyyy-mm-dd'. I would like to be able to run this script by providing a link to the specific folder in my Dropbox account. If you have any simpler code snippet for it, I'd be happy to see that.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 3 hours agoIf 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 or Facebook.
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!