python 批量給檔名新增字尾

Rosinante.發表於2020-10-24
import os


def batch_rename(dir_path, suffix):
    files = os.listdir(dir_path)
    for i, file in enumerate(files):
        old_name = os.path.join(dir_path, file)
        new_name = os.path.join(dir_path, file.split(".")[0] + suffix + '.' + file.split(".")[-1])
        os.rename(old_name, new_name)

 

相關文章