Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Recursively uploads a directory structure to Synapse
import os
import synapseclient
from synapseclient import File, Folder
PROJECT = 'syn2778315'
for dirpath, dirnames, filenames in os.walk(START_PATH):
#Add the subfolders
for dirname in dirnames:
print 'creating', dirname
f =, parent = parents[dirpath]))
parents[os.path.join(dirpath, dirname)] =
#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, forceVersion=False) #optionally add, 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