python 批量修改特定后缀文件的文件名

import os
import glob

# 找出.jpg格式文件,修改名字
project_path = r"E:\"
img_type = "jpg"
img_path = glob.glob(os.path.join(project_path, '*.'+ img_type))
num = 1
for file in img_path:
    _, used_name = os.path.split(file)
    new_name = str(num)+ '.'+ img_type
    print(used_name, new_name)
    os.rename(os.path.join(project_path,used_name),os.path.join(project_path,new_name))
    num += 1

你可能感兴趣的:(python 批量修改特定后缀文件的文件名)