Last active
January 30, 2021 02:50
-
-
Save cbare/45cc37ef3758816618f1 to your computer and use it in GitHub Desktop.
Example of how to upload a directory hierarchy into a Synapse project
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 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