.jpg改为.jpeg,还可以修改成其他的格式
import os
import string
dirName = r"C:\Users\Lenovo\Desktop\mydataset\JPEGImages\\" #最后要加双斜杠,不然会报错
li=os.listdir(dirName)
for filename in li:
newname = filename
newname = newname.split(".")
if newname[-1]=="jpg":
newname[-1]="jpeg"
newname = str.join(".",newname) #这里要用str.join
filename = dirName+filename
newname = dirName+newname
os.rename(filename,newname)
print(newname,"successfully")