Sometimes is the return code of running dcm2niix success even though no nii files, therefore no json files were produced. This means that jsonfiles will need to remove <outfolder/bidsname.json> as it doesn't exist.
This code changes jsonfiles to set and only adds jsonfiles if they exist, meaning no need of removing nonexistent jsonfiles.
Maybe continue can be added not only for if return code is not success, but also if no nii files are produced?
Sometimes is the return code of running dcm2niix success even though no nii files, therefore no json files were produced. This means that jsonfiles will need to remove <outfolder/bidsname.json> as it doesn't exist.
This code changes jsonfiles to set and only adds jsonfiles if they exist, meaning no need of removing nonexistent jsonfiles. Maybe continue can be added not only for if return code is not success, but also if no nii files are produced?