批量修改图片名称 python
程序员文章站
2022-04-18 20:03:41
...
def rename():
path = "./2/"
filelist = os.listdir(path)
total_num = len(filelist)
i = 1
for item in filelist:
if item.endswith('.png'):
old = os.path.join(os.path.abspath(path), item)
print('src', src)
new = os.path.join(os.path.abspath('./1/'), '' + str(i) + '.png')
print('dst', dst)
try:
# src:原名称 dst新名称
os.rename(old, new)
i += 1
except:
continue