Skip to content

Commit ed00ef5

Browse files
committed
Adding example to changeFileMetaData
1 parent 31d0906 commit ed00ef5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

synapseutils/copy_functions.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,37 @@ def changeFileMetaData(
260260
Synapse Entity
261261
262262
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:
264294
265295
file_entity = syn.get(synid)
266296
print(os.path.basename(file_entity.path)) ## prints, e.g., "my_file.txt"

0 commit comments

Comments
 (0)