diff --git a/fsl/data/image.py b/fsl/data/image.py index 1b407a3f7c773066c13e75b5bb207de03986f9c3..a1e695b59bd81a36a845d3f64167efbf6222ecc5 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -1376,6 +1376,20 @@ def removeExt(filename): return fslpath.removeExt(filename, ALLOWED_EXTENSIONS) +def fixExt(filename): + """Fix the extension of ``filename``. + + For example, if a file name is passed in as ``file.nii.gz``, but the + file is actually ``file.nii``, this function will fix the file name. + + If ``filename`` already exists, it is returned unchanged. + """ + if op.exists(filename): + return filename + else: + return addExt(removeExt(filename)) + + def defaultExt(): """Returns the default NIFTI file extension that should be used.