Last active
August 29, 2015 14:08
-
-
Save larssono/db35917cf58440fe0b19 to your computer and use it in GitHub Desktop.
Recursively uploads a directory structure to Synapse
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
import os | |
import synapseclient | |
from synapseclient import File, Folder | |
PROJECT = 'syn2778315' | |
START_PATH = '.' | |
syn=synapseclient.login(silent=True) | |
parents = {START_PATH: PROJECT} | |
for dirpath, dirnames, filenames in os.walk(START_PATH): | |
#Add the subfolders | |
for dirname in dirnames: | |
print 'creating', dirname | |
f = syn.store(Folder(dirname, parent = parents[dirpath])) | |
parents[os.path.join(dirpath, dirname)] = f.id | |
#Add the files | |
for name in filenames: | |
path = os.path.join(dirpath, name) | |
if os.stat(path).st_size>0: | |
print 'uploading', path | |
f = File(path, parent = parents[dirpath], name=name) | |
#f.fileType = name[-3:] | |
#f.project = 'Cool imaging library | |
syn.store(f, forceVersion=False) #optionally add syn.store(f, used='http://..) to sepcify the source location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment