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
avieini
6 years agoNew member | Level 2
Iterating and Downloading from shared link subfolders
Hi all,
I have a shared link looking like this: https://www.dropbox.com/sh/o0qb...
In this link I have folders and subfolder and some heavy files in them.
I searched across the web and didn't find anything that could help me.
I basically want to be able to iterate over the folders and the subfolders and download files from specific subfolders.
I am working with Python and the best I could do so far was retrieve the subfolders names and id's (by using this theard )
Do you have any idea how to tackle it?
Thanks!
- Pikamander2Experienced | Level 13
Here's the HTTP documentation and here's the Python documentation (see the dropbox.dropbox subpage).
For HTTP requests, the /download, /get_shared_link_file, and /list_folders endpoints sound like they would be helpful.
For the Python library, check out the files_download, files_download_to_file, and files_list_folder functions.
The dropbox API is very complex, so you'll need to read through the documentation to see what all is available.
- Greg-DBDropbox Staff
avieini Yes, as Pikamander2 mentioned, there are some methods that can help with this, like files_list_folder from the thread you linked to, as well as sharing_get_shared_link_file.
Here's a basic example of what using those may look like:
import dropbox ACCESS_TOKEN = "..." url = "https://www.dropbox.com/sh/..." dbx = dropbox.Dropbox(ACCESS_TOKEN) shared_link = dropbox.files.SharedLink(url=url) print(dbx.files_list_folder(path="", shared_link=shared_link)) filename = "..." print(dbx.sharing_get_shared_link_file(url=url, path=filename))
- avieiniNew member | Level 2
Hi Greg, thanks for your answer
The point that I get confused with is how do I (iteratively) acess the subfolders of the main folder ?
The files_list_folder method only gives me the names and the ids of those subfolders.
If I could "enter" each subfolder I would be able to downlaod it's files.
Hope now it's clearer.
- Greg-DBDropbox Staff
avieini While the 'files_list_folder' method does not support the native 'recursive' mode when listing from a shared link, you can iteratively list out the contents of the subfolders, by calling again with the relevant 'path' value(s). For example, say if I make the first call:
print(dbx.files_list_folder(path="", shared_link=shared_link))
If that shows me that there is a subfolder with a 'name' of 'another folder', for example, I can then call again to list that one, like:
print(dbx.files_list_folder(path="/another folder", shared_link=shared_link))
That will give the listing for that subfolder, and then likewise I can call 'sharing_get_shared_link_file' to download a file from inside that subfolder, like:
print(dbx.sharing_get_shared_link_file(url=url, path="/another folder/test.txt"))
About Discuss Dropbox Developer & API
Make connections with other developers
795 PostsLatest Activity: 12 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!