add suffix to multiple file names python

Solutions on MaxInterview for add suffix to multiple file names python by the best coders in the world

showing results for - "add suffix to multiple file names python"
Amelia
10 Apr 2018
1from glob import glob
2import os
3pre = "xyz_"
4[os.rename(f, "{}{}".format(pre, f)) for f in glob("*.html")]
5
Paola
04 Jun 2020
1def add_suffix(fname, suffix):
2    """
3    Add suffix between end of file name and extension.
4
5    :param fname: absolute or relative file name. Example: t2.nii
6    :param suffix: suffix. Example: _mean
7    :return: file name with suffix. Example: t2_mean.nii
8
9    Examples:
10
11    - add_suffix(t2.nii, _mean) -> t2_mean.nii
12    - add_suffix(t2.nii.gz, a) -> t2a.nii.gz
13    """
14    parent, stem, ext = extract_fname(fname)
15    return os.path.join(parent, stem + suffix + ext)
16
17
18#=======================================================================================================================
19# run
20#=======================================================================================================================
21# Run UNIX command