How to batch rename folders and files in Python

Add characters to the end of all file and folder names

import os
dir_path = "./dirname"
dir_list = os.listdir(dir_path)
for i in range(len(dir_list)):
    new_file_name = dir_list[i] + "!!!"

How to modify or remove only certain characters from file and folder names

import os
import glob

before_word = "!!!"
after_word = ""

files = glob.glob('*'+ before_word +'*')
for before_file_name in files:
    after_file_name = before_file_name.replace(before_word,after_word)


Copied title and URL