import os
# 图片所在路径
root_path = "license_plate/green/"
filename_list = os.listdir(root_path)
for filename in filename_list:
if filename.endswith('.jpg'):
src_img_path = os.path.join(os.path.abspath(root_path), filename)
dst_img_path = os.path.join(os.path.abspath(root_path), filename.split('_')[1])
try:
os.rename(src_img_path, dst_img_path)
print('converting %s to %s ...' % (src_img_path, dst_img_path))
except:
continue
python用下划线后半分部分重命名文件夹下的图片
最新推荐文章于 2024-09-14 10:38:48 发布
本文介绍了一种使用Python批量重命名指定目录下.jpg格式图片的方法。通过遍历指定路径下的所有文件,仅针对以.jpg结尾的文件进行重命名操作,并采用新的文件名。此过程涉及读取文件列表、构建新旧文件路径并执行重命名。
2217

被折叠的 条评论
为什么被折叠?



