import os
def filerename(path):
for fn in os.listdir(path):
x = 1
if fn.endswith('.jpg'):
oldname = os.path.join(path, fn)
newname = str(x)
os.rename(oldname,newname+ '.jpg')
x +=1
if name == 'main':
filerename('F:\npp.7.5.8.bin.x64\test')
报错:
Traceback (most recent call last):
File "C:\Users\luckytown\Desktop\py\rename.txt", line 13, in <module>
filerename('F:\npp.7.5.8.bin.x64\test')
File "C:\Users\luckytown\Desktop\py\rename.txt", line 9, in filerename
os.rename(oldname,newname+ '.jpg')
FileExistsError: [WinError 183] 当文件已存在时,无法创建该文件。: 'F:\npp.7.5.8.bin.x64\test\1555992697.0300374.jpg' -> '1.jpg'
请按任意键继续. . .