File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -260,7 +260,37 @@ def changeFileMetaData(
260
260
Synapse Entity
261
261
262
262
Example: Using this function
263
- Can be used to change the filename, the filename when the file is downloaded, or the file content-type without downloading:
263
+ Updating all file 'downloadAs' names within a folder to match the name of the
264
+ entity.
265
+
266
+ import synapseclient
267
+ import synapseutils
268
+
269
+
270
+ syn = synapseclient.Synapse()
271
+ syn.login()
272
+
273
+ MY_FOLDER_TO_UPDATE_ALL_FILES_IN = "syn123"
274
+
275
+ for files_to_update in syn.getChildren(
276
+ parent=MY_FOLDER_TO_UPDATE_ALL_FILES_IN, includeTypes=["file"]
277
+ ):
278
+ file_to_check = syn.get(files_to_update["id"], downloadFile=False)
279
+ if file_to_check.name != file_to_check["_file_handle"]["fileName"]:
280
+ print(
281
+ f"Updating downloadAs for {file_to_check['_file_handle']['fileName']} to {file_to_check.name}"
282
+ )
283
+
284
+ synapseutils.changeFileMetaData(
285
+ syn=syn,
286
+ entity=file_to_check.id,
287
+ downloadAs=file_to_check.name,
288
+ forceVersion=False,
289
+ )
290
+
291
+
292
+ Can be used to change the filename, the filename when the file is downloaded,
293
+ or the file content-type without downloading:
264
294
265
295
file_entity = syn.get(synid)
266
296
print(os.path.basename(file_entity.path)) ## prints, e.g., "my_file.txt"
You can’t perform that action at this time.
0 commit comments