python进行文件批量命名

目录

1、传递需要修改文件的上一级目录root_path,step的作用是生成不同的文件,convert_format是转化为特定的格式

2、代码使用 


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)

相关推荐

  1. python进行文件批量命名

    2023-12-07 05:02:05       37 阅读
  2. 音视频文件批量转换并重命名python

    2023-12-07 05:02:05       40 阅读
  3. python项目练习——5.自动化批量命名图片文件

    2023-12-07 05:02:05       18 阅读
  4. Python文件命名规则:批量命名与规则匹配的文件

    2023-12-07 05:02:05       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-07 05:02:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-07 05:02:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-07 05:02:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-07 05:02:05       20 阅读

热门阅读

  1. 如何快速移植(从STM32F103到STM32F407)

    2023-12-07 05:02:05       43 阅读
  2. 用两个栈实现队列(c++实现)

    2023-12-07 05:02:05       38 阅读
  3. praseInt 和 逻辑或连用

    2023-12-07 05:02:05       30 阅读
  4. SpringMVC常用注解

    2023-12-07 05:02:05       25 阅读
  5. Spring Boot学习(三十三):集成kafka

    2023-12-07 05:02:05       48 阅读
  6. RK3288升级WebView版本,替换webview app

    2023-12-07 05:02:05       36 阅读
  7. android 13.0 Camera2去掉前置摄像头闪光灯功能

    2023-12-07 05:02:05       38 阅读
  8. ThreadLocal+TaskDecorator实现父子线程 参数传递

    2023-12-07 05:02:05       39 阅读