Created
June 30, 2015 05:35
-
-
Save feelinc/a0b241762a31d9fa14fe to your computer and use it in GitHub Desktop.
Upload folder content to Dropbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
from dropbox.client import DropboxClient | |
# get an access token, local (from) directory, and Dropbox (to) directory | |
# from the command-line | |
access_token, local_directory, dropbox_destination = sys.argv[1:4] | |
client = DropboxClient(access_token) | |
# enumerate local files recursively | |
for root, dirs, files in os.walk(local_directory): | |
for filename in files: | |
# construct the full local path | |
local_path = os.path.join(root, filename) | |
# construct the full Dropbox path | |
relative_path = os.path.relpath(local_path, local_directory) | |
dropbox_path = os.path.join(dropbox_destination, relative_path) | |
# check if local path already exist | |
print 'Searching "%s" for "%s"' % (dropbox_path.replace('/' + filename, ''), filename) | |
found = client.search(dropbox_path.replace('/' + filename, ''), filename) | |
# upload the file | |
if found: | |
print "Path found on Dropbox, this shouldn't happen! Skipping %s..." % filename | |
else: | |
with open(local_path, 'rb') as f: | |
client.put_file(dropbox_path, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UploadDirDropbox.py thedropboxaccesstoken /path/to/local/folder /path/to/dropbox/folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment