NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.filename_parser.parse_filename

Next topic

nibabel.filename_parser.types_filenames

Reggie -- the one

nibabel.filename_parser.splitext_addext

nibabel.filename_parser.splitext_addext(filename, addexts=('.gz', '.bz2'), match_case=False)

Split /pth/fname.ext.gz into /pth/fname, .ext, .gz

where .gz may be any of passed addext trailing suffixes.

Parameters :

filename : str

filename that may end in any or none of addexts

match_case : bool, optional

If True, match case of addexts and filename, otherwise do case-insensitive match.

Returns :

froot : str

Root of filename - e.g. /pth/fname in example above

ext : str

Extension, where extension is not in addexts - e.g. .ext in example above

addext : str

Any suffixes appearing in addext occuring at end of filename

Examples

>>> splitext_addext('fname.ext.gz')
('fname', '.ext', '.gz')
>>> splitext_addext('fname.ext')
('fname', '.ext', '')
>>> splitext_addext('fname.ext.foo', ('.foo', '.bar'))
('fname', '.ext', '.foo')