import os
import re
#coding=utf-8
n = 464
def ReFigName(dirPath):
global n
####param dirPath: 文件夹路径
# 对目录下的文件进行遍历
for file in os.listdir(dirPath):
print(file)
# 判断是否是文件
if os.path.isfile(os.path.join(dirPath, file)) == True:
newfile = str(n) + ".jpg"##在此处修改自己想要的图片名即可
n += 1
# 重命名
os.rename(os.path.join(dirPath, file), os.path.join(dirPath, newfile))
print(newfile)
if __name__ == '__main__':
dirPath = r"C:/Users/LI/Desktop/Code/conda python/cfdata"###添加自己的文件路径即可
ReFigName(dirPath)
python 自动修改文件名
于 2022-07-18 12:18:56 首次发布