Answers for "add suffix to multiple file names python"

0

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
Posted by: Guest on July-20-2021
0

add suffix to multiple file names python

from glob import glob
import os
pre = "xyz_"
[os.rename(f, "{}{}".format(pre, f)) for f in glob("*.html")]
Posted by: Guest on July-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language