I have a script that is intended to be run by multiple users on multiple computers, and they don't all have their Dropbox folders in their respective home directories. I'd hate to have to hard code paths in the script. I'd much rather figure out the path programatically.
Any suggestions welcome.
EDIT: I am not using the Dropbox API in the script, the script simply reads files in a specific Dropbox folder shared between the users. The only thing I need is the path to the Dropbox folder, as I of course already know the relative path within the Dropbox file structure.
EDIT: If it matters, I am using Windows 7.
After you install the Dropbox desktop app, you can find the default location of Dropbox in your File Explorer (Windows) or Finder (Mac). It will be named “Dropbox”. Open Windows Explorer. Type %HOMEPATH%/Dropbox into the address bar.
If you haven't set a file or folder to online-only, then all files and folders in the Dropbox folder on your computer are available offline. This means that they take up space both on your computer's hard drive and in your Dropbox account, but are available even when you're not connected to the Internet.
See all of your shared Dropbox files and folders Just go to dropbox.com/share—or click Shared in the Dropbox web app sidebar. There, you'll see all of your shared files and folders and can edit any of them directly. Or you can create a new shared folder to share more stuff.
To see metadata about your file: Sign in to dropbox.com. Hover over the file and click the checkbox. The file information will be located in the details pane of the right sidebar.
I found the answer here. Setting s
equal to the 2nd line in ~\AppData\Roaming\Dropbox\host.db
and then decoding it with base64 gives the path.
def _get_appdata_path():
import ctypes
from ctypes import wintypes, windll
CSIDL_APPDATA = 26
_SHGetFolderPath = windll.shell32.SHGetFolderPathW
_SHGetFolderPath.argtypes = [wintypes.HWND,
ctypes.c_int,
wintypes.HANDLE,
wintypes.DWORD,
wintypes.LPCWSTR]
path_buf = wintypes.create_unicode_buffer(wintypes.MAX_PATH)
result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, path_buf)
return path_buf.value
def dropbox_home():
from platform import system
import base64
import os.path
_system = system()
if _system in ('Windows', 'cli'):
host_db_path = os.path.join(_get_appdata_path(),
'Dropbox',
'host.db')
elif _system in ('Linux', 'Darwin'):
host_db_path = os.path.expanduser('~'
'/.dropbox'
'/host.db')
else:
raise RuntimeError('Unknown system={}'
.format(_system))
if not os.path.exists(host_db_path):
raise RuntimeError("Config path={} doesn't exists"
.format(host_db_path))
with open(host_db_path, 'r') as f:
data = f.read().split()
return base64.b64decode(data[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With