How to determine the Dropbox folder location programmatically?

前端 未结 8 1154
故里飘歌
故里飘歌 2020-12-06 09:38

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

相关标签:
8条回答
  • 2020-12-06 10:34

    There is an answer to this on Dropbox Help Center - How can I programmatically find the Dropbox folder paths?

    Short version:

    Use ~/.dropbox/info.json or %APPDATA%\Dropbox\info.json

    Long version:

    Access the valid %APPDATA% or %LOCALAPPDATA% location this way:

    import os
    from pathlib import Path
    import json
    
    try:
        json_path = (Path(os.getenv('LOCALAPPDATA'))/'Dropbox'/'info.json').resolve()
    except FileNotFoundError:
        json_path = (Path(os.getenv('APPDATA'))/'Dropbox'/'info.json').resolve()
    
    with open(str(json_path)) as f:
        j = json.load(f)
    
    personal_dbox_path = Path(j['personal']['path'])
    business_dbox_path = Path(j['business']['path'])
    
    0 讨论(0)
  • 2020-12-06 10:39

    One option is you could go searching for the .dropbox.cache directory which (at least on Mac and Linux) is a hidden folder in the Dropbox directory.

    I am fairly certain that Dropbox stores its preferences in an encrypted .dbx container, so extracting it using the same method that Dropbox uses is not trivial.

    0 讨论(0)
提交回复
热议问题