Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recursively uploads a directory structure to Synapse
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
You can’t perform that action at this time.