Alexis Eggermont Alexis Eggermont - 1 year ago 150
Python Question

Find personal Dropbox folder path with Python

I have found this thread. The answer suggested there works on my Mac, but not my Windows machine.

The last comment on the accepted answer mentions that "The dropbox host.db file doesn't exist anymore in latest version." so it seems the solution doesn't work anymore.

I've also found this official guide, but the suggested code gives me an error

import json
from pprint import pprint
with open('%LOCALAPPDATA%\Dropbox\info.json') as data_file:
data = json.load(data_file)

IOError: [Errno 2] No such file or directory: '%LOCALAPPDATA%\\Dropbox\\info.json'

An additional complication is that I have a personal and professional dropbox account on each machine. The personal folder is called 'Dropbox (Personal)'.

Any pointers on how to find this folder path on any machine where I've synced my Dropbox?

Answer Source

Either install the pip package: winpaths and then do:

import winpaths
appdata_path = winpaths.get_local_appdata()

or, do:

import os
appdata_path = os.getenv('LOCALAPPDATA')

and then, eventually:

with open(os.path.join(appdata_path, 'Dropbox', 'info.json')) as data_file:

If you want to try out App Data directory instead of Local App Data directory, then in the above code, replace LOCALAPPDATA with APPDATA or get_local_appdata() with get_appdata()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download