python 批量重命名文件


# -*- coding: utf-8 -*-
import os
import sys


def rename():
    path = input("路径(例如D:\\\\picture):")
    name = input("新文件开头名:")
    startNumber = input("起始数字:")
    fileType = input("文件类型(如 .jpg、.txt等等):")   
    count = 0
    filelist = os.listdir(path)
    for file in filelist:
        oldF = os.path.join(path, file)
        if os.path.isfile(oldF) and os.path.splitext(oldF)[1] == fileType:
            newF = os.path.join(
                path, name+str(count+int(startNumber))+fileType)
            os.rename(oldF, newF)
        else:
            continue
        count += 1
    print("一共修改了"+str(count)+"个文件")


rename()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM