code: def splitext(fname):
      
      from pathlib import Path
      basename = str(Path(fname).name)
      stem = Path(basename.rstrip('.gz')).stem
      return stem, basename[len(stem):]
docs: Splits filename and extension (.gz safe)
  
      >>> splitext('some/file.nii.gz')
      ('file', '.nii.gz')
      >>> splitext('some/other/file.nii')
      ('file', '.nii')
      >>> splitext('otherext.tar.gz')
      ('otherext', '.tar.gz')
      >>> splitext('text.txt')
      ('text', '.txt')