diff --git a/nipype/interfaces/dcm2nii.py b/nipype/interfaces/dcm2nii.py index b78d925517..5c5eb4e134 100644 --- a/nipype/interfaces/dcm2nii.py +++ b/nipype/interfaces/dcm2nii.py @@ -139,11 +139,13 @@ def _parse_stdout(self, stdout): else: output_dir = self._gen_filename('output_dir') val = os.path.join(output_dir, val) - out_file = val + if os.path.exists(val): + out_file = val if out_file: - files.append(out_file) - last_added_file = out_file + if not out_file in files: + files.append(out_file) + last_added_file = out_file continue if line.startswith("Reorienting as "): @@ -153,9 +155,12 @@ def _parse_stdout(self, stdout): elif line.startswith("Cropping NIfTI/Analyze image "): base, filename = os.path.split(line[len("Cropping NIfTI/Analyze image "):]) filename = "c" + filename - reoriented_and_cropped_files.append(os.path.join(base, filename)) - skip = True - continue + if os.path.exists(os.path.join(base, filename)) or self.inputs.reorient_and_crop: + # if reorient&crop is true but the file doesn't exist, this errors when setting outputs + reoriented_and_cropped_files.append(os.path.join(base, filename)) + skip = True + continue + skip = False return files, reoriented_files, reoriented_and_cropped_files, bvecs, bvals