#!/usr/bin/python# -*- coding:utf-8 -*-import osimport randomdef reanme():img_path = os.getcwd() + '/img'img_list = os.listdir(img_path)for img in img_list:if img.endswith('.jpg'):src = os.path.join(os.path.abspath(img_path), img) # 原先的图片名字# 根据自己的需要重新命名,可以把 + img改成你想要的名字re_img = img.split('.')[0][1:3] + "." + img.split('.')[1]dst = os.path.join(os.path.abspath(img_path),f'_{str(random.random()).replace(".", "")[0:8]}_{re_img}')os.rename(src, dst) # 重命名,覆盖原先的名字reanme()
