From b1cf43e6e8e325fdd80ba64c4ff3b209676d91fa Mon Sep 17 00:00:00 2001 From: valosekj Date: Sat, 13 May 2023 09:12:30 -0400 Subject: [PATCH] Add condition to check if JSON sidecar exists. If not, do not raise error, instead, print warning. --- copy_files_to_derivatives.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/copy_files_to_derivatives.py b/copy_files_to_derivatives.py index f87d0d5..aa4b9a6 100644 --- a/copy_files_to_derivatives.py +++ b/copy_files_to_derivatives.py @@ -84,8 +84,11 @@ def main(): print(f'Copying: {path_file_in} to {path_file_out}') path_file_json_in = path_file_in.replace('nii.gz', 'json') path_file_json_out = path_file_out.replace('nii.gz', 'json') - shutil.copy(path_file_json_in, path_file_json_out) - print(f'Copying: {path_file_json_in} to {path_file_json_out}') + if os.path.isfile(path_file_json_in): + shutil.copy(path_file_json_in, path_file_json_out) + print(f'Copying: {path_file_json_in} to {path_file_json_out}') + else: + print(f'Warning: {path_file_json_in} does not exist.') if __name__ == '__main__':