import os,random
path='D:\图片\人脸 男\人脸1/'
f = os.listdir(path)
count = 0
for i in f:
# 设置旧文件名(就是路径+文件名)
sub = random.randint(1, 10000)
oldname = path+f[count]
# 设置新文件名
newname = path +'%s_'%sub+ str(count + 1) + '.JPG'
# 用os模块中的rename方法对文件改名
os.rename(oldname,newname)
print(oldname, '======>', newname)
count += 1