path = "C:\\Users\\Administrator\\Desktop\\testB"# 文件路径 a = 1 for file in os.listdir(path): b = os.path.join(path, file) if os.path.isfile(os.path.join(path, file))==True: newname = "{}.png".format(a) os.rename(os.path.join(path, file), os.path.join(path, newname)) print(file, "ok") a = a+1