From dba468d264056cc0813387ced0a5193165d9c513 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Thu, 22 Nov 2018 14:50:59 +0000
Subject: [PATCH] ENH: New function fixExt to fix image extensions.

---
 fsl/data/image.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 1b407a3f7..a1e695b59 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.
 
-- 
GitLab