Search code examples
pythondropbox-api

How do I get the path and info of Dropbox files using python API


I am using the python Dropbox API and I am trying to get the path and media file of each file so I can reorganize my Dropbox account.

Presently, my code is below and I in testing, the media_info has no output (these are all video files) and in reading the documentation I can't figure out how to list my path.

So, I would like to get:

  1. path of file
  2. Media info of file

app.py

dbx = dropbox.Dropbox('xxxxxx')
result = dbx.files_list_folder("", recursive=True)
file_list = []

i = 1
for entry in dbx.files_list_folder("").entries:
    if isinstance(entry, dropbox.files.FileMetadata):
        print(entry.name)
        print(entry.size / 1000000)
        print(entry.media_info)
        print(f'The  number is {i}')
        i= i + 1

output

sci_2003_toothbrush_injury_study.mov
215.624412
None
The  number is 1
edu_2003_stem_saturdays.mov
457.252114
None
The  number is 2
boo_202004_eduardo_porter.mov
2889.928171
None
The  number is 3

Solution

  • For get full path use instance dropbox.files.FileMetadata for example:

    import dropbox
    from dropbox.files import FolderMetadata
    
    
    def printListFilesRecursive():
        dbx = dropbox.Dropbox('XXXXXXXX')
    
        # Use recursive=True for scan recursive folder.
        for entry in dbx.files_list_folder('', recursive=True).entries:
            # Use instance FileMetadata for get more information of entry
            if isinstance(entry, dropbox.files.FileMetadata):
                print(entry.path_display)
    
    
    if __name__ == '__main__':
        printListFilesRecursive()
    
    

    Output:

    /PokemonGo Maps 1.0 Versión original/transform.py
    /PokemonGo Maps 1.0 Versión original/transform.pyc
    /PokemonGo Maps 1.0 Versión original/npm-debug.log
    /Screenshots/Screenshot 2016-10-19 17.01.50.png
    /Screenshots/Screenshot 2016-10-19 17.02.08(3).png