目录
1、传递需要修改文件的上一级目录root_path,step的作用是生成不同的文件,convert_format是转化为特定的格式
1、传递需要修改文件的上一级目录root_path,step的作用是生成不同的文件,convert_format是转化为特定的格式
import os
def convert(root_path, step, convert_format):
"""
root_paht: 根目录路径
step:步长开始
convert_format:转换文件格式
"""
images_name_list = os.listdir(root_path)
for image_name in images_name_list:
src_image_path = os.path.join(root_path, image_name)
print("原文件名称",src_image_path)
dst_image_path = os.path.join(root_path, "{}".format(step)+"{}".format(convert_format))
print("修改名称",dst_image_path)
os.rename(src_image_path, dst_image_path)
step += 1
2、代码使用
root_path = "F:\\image\\image_data\\1\\163_293"
step = 163
convert_format = '.jpg'
convert(root_path=root_path,step=step, convert_format=convert_format)