0

Using Dropbox APIs, I am able to get view of all the folders in the root folder and using metadata, I can print all the information from JSON on the screen.

For example, a sample output would be like

{
    'bytes': 0,
    'contents': [
        {
           'bytes': 0,
           'icon': 'folder',
           'is_dir': True,
           'modified': 'Thu, 25 Aug 2011 00:03:15 +0000',
           'path': '/Sample Folder',
           'rev': '803beb471',
           'revision': 8,
           'root': 'dropbox',
           'size': '0 bytes',
           'thumb_exists': False
        }, 
        {
           'bytes': 77,
           'icon': 'page_white_text',
           'is_dir': False,
           'mime_type': 'text/plain',
           'modified': 'Wed, 20 Jul 2011 22:04:50 +0000',
           'path': '/magnum-opus.txt',
           'rev': '362e2029684fe',
           'revision': 221922,
           'root': 'dropbox',
           'size': '77 bytes',
           'thumb_exists': False
        }
    ],
    'hash': 'efdac89c4da886a9cece1927e6c22977',
    'icon': 'folder',
    'is_dir': True,
    'path': '/',
    'root': 'app_folder',
    'size': '0 bytes',
    'thumb_exists': False
}

I am not sure, how can I get elements of 'contents' array and then recursively, get files using 'path' attribute.

And my ultimate goal is to get list of all files in Dropbox folder. Is there any better way to get list of all files?

I have tried following code:

folder_metadata = self.api_client.metadata('/Photos')
print "-----------------------------"
print "path:", folder_metadata['path']
for s in folder_metadata['contents']:
    for dirname, dirnames, filenames in os.walk(s['path']):
        for filename in filenames:
            var = os.path.join(dirname, filename)
            print var

and its output is:

-----------------------------
path: /Photos

How can I get an absolute path?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Junaid
  • 1,668
  • 7
  • 30
  • 51
  • Do you have the same files on your harddisk (as synchronized by Dropbox)? – Martijn Pieters Jan 28 '13 at 10:47
  • Yes, I think, it needs an absolute path for 'path' to find out all the files in the folder. I have tried the same code with hard-coded absolute path and it does give me list of files. So, all I need is absolute path. – Junaid Jan 28 '13 at 11:09
  • I tried this solution (http://stackoverflow.com/questions/12118162/how-can-i-get-the-dropbox-folder-location-programmatically-in-python) but it checks for 'hosts.db' which is in C: folder but my own Dropbox folder is in E: , so this is wrong. – Junaid Jan 28 '13 at 11:10
  • You are correct you need a path, and that question you link to should provide the correct answer; the top-voted answer retrieves the registry key that Dropbox itself has set; if your dropbox folder is on E: then that's a problem with Dropbox itself and I don't think there is anything we can do about that from Python. – Martijn Pieters Jan 28 '13 at 11:55
  • In any case, the API does *not* provide you with the local path for your Dropbox files. That is the responsibility of the Dropbox application installed on your machine instead. – Martijn Pieters Jan 28 '13 at 11:56
  • Did you check [this script](http://www.dropboxwiki.com/PyDropboxValues) yet? It's linked in a comment on the other question. – Martijn Pieters Jan 28 '13 at 11:57
  • "An error occured: Unhandled DB schema version 2" Thats what I got from that script. Anywya, thank you Martijn for your help. I will provide path to Dropbox to my function now. =) – Junaid Jan 28 '13 at 12:10

0 Answers0