解决方案
#!usr/bin/env python# -*- coding:utf-8 _*-"""@version: 0.0.1@author: ShenTuZhiGang@time: /03/09 19:52@file: renamedemo.py@function:@last modified by: ShenTuZhiGang@last modified time: /03/09 19:52"""import imghdrimport osdef rename():path = input("请输入路径(例如D:\\\\picture):")name = input("请输入开头名:")start_number = int(input("请输入开始数:"))print("正在生成以" + name + str(start_number) + "迭代的文件名")file_list = os.listdir(path)for files in file_list:old_dir = os.path.join(path, files)if os.path.isdir(old_dir):continuenew_dir = os.path.join(path, name + str(start_number) + "." + imghdr.what(old_dir))os.rename(old_dir, new_dir)start_number += 1print("一共修改了" + str(len(file_list)) + "个文件")rename()
参考文章
Python对文件批量重命名