Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of how to upload a directory hierarchy into a Synapse project
import synapseclient
from synapseclient import Synapse, File, Folder, Project
import os
def upload_recursive(directory, parent):
for item in os.listdir(directory):
if os.path.isdir(os.path.join(directory,item)):
print "%s/" % os.path.basename(item)
folder = syn.store(Folder(os.path.basename(item), parent=parent))
upload_recursive(directory=os.path.join(directory, item), parent=folder)
else:
print os.path.basename(item)
file1 = syn.store(File(os.path.join(directory,item), parent=parent))
syn = Synapse()
syn.login()
## insert the ID for your project here:
my_project = 'syn2358458'
parent = syn.get(my_project)
upload_recursive('.', parent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment