Rename multiple filename with python 您所在的位置:网站首页 rename_drawings_with_object Rename multiple filename with python

Rename multiple filename with python

2023-03-30 08:26| 来源: 网络整理| 查看: 265

You could use something like this to list all contents of the directory, pull the student id's, find the file type, and create a new name and save it in the same directory:

import os # full directory path to student pictures student_pic_path = 'full directory path to student pics' # get all student picture filenames from path fnames = os.listdir(student_pic_path) # iterate over each picture for fname in fnames: # split by underscore and capture student id name new_name = fname.split('_')[0] # get the file type file_type = fname.split('.')[-1] # append file type to new name new_name = '{}.{}'.format(new_name, file_type) os.rename(os.path.join(student_pic_path, fname), os.path.join(student_pic_path, new_name))


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有