Forum Discussion

avieini's avatar
avieini
New member | Level 2
6 years ago

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!

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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))
    
    • avieini's avatar
      avieini
      New 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-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox 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"))