import os directory = '_static/Image' for file in os.scandir(directory): if file.path.endswith(".PNG"): new_name = file.path.replace(".PNG", ".png") os.rename(file.path, new_name)