python一括ファイル名の変更

4711 ワード

# -*- 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()

転送元:python一括名前変更ファイル