收集了一批数据,有2000张图片,但是每张图片的名字都不一样,比如as.png
或者12.png
或者ss2.png
,现在将他们进行批量命名,从1.png
到2000.png
import os
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