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