add suffix to multiple file names python
def add_suffix(fname, suffix):
"""
Add suffix between end of file name and extension.
:param fname: absolute or relative file name. Example: t2.nii
:param suffix: suffix. Example: _mean
:return: file name with suffix. Example: t2_mean.nii
Examples:
- add_suffix(t2.nii, _mean) -> t2_mean.nii
- add_suffix(t2.nii.gz, a) -> t2a.nii.gz
"""
parent, stem, ext = extract_fname(fname)
return os.path.join(parent, stem + suffix + ext)
#=======================================================================================================================
# run
#=======================================================================================================================
# Run UNIX command