#! /usr/bin/python import os exts = [".264", ".mkv", ".mp4", ".mpeg", ".mpg", ".mov", ".avi", ".wmv", ".idx", ".sub", ".srt"] #list of valid file extensions splitdir = os.getcwd().split("\\") #return array of the current working director, split by folders nameinfo = splitdir[-2:] #make new array with last two elements of splitdir (Show name, season number) if int(nameinfo[1]) < 10 and len(nameinfo[1]) < 2: #if the folder number is from 1-9 start = nameinfo[0]+".S"+nameinfo[1].zfill(2)+"E" #make a variable and fill with .S.E" else: #anything higher than 10, or zero padded start = nameinfo[0]+".S"+nameinfo[1]+"E" end = ".HDTV.XviD-2HD" #release type tag def rename(): loops = 1 for file in os.listdir("."): if file == "rename.py": pass elif os.path.isdir(file): pass else: extension = os.path.splitext(file)[1] #get file extension if extension in exts: #check it against the list of accepted extensions if loops < 10: #check if the episode number will need zero padding newname = start+str(loops).zfill(2)+end #create the new name from previously collected info os.rename(file, newname+extension) #rename it add the file extension back on elif os.path.isfile(file): newname = start+str(loops)+end os.rename(file, newname+extension) loops+=1 def check(): loops = 1 for file in os.listdir("."): if file == "rename.py": pass elif os.path.isdir(file): pass else: extension = os.path.splitext(file)[1] if extension in exts: if loops < 10: newname = start+str(loops).zfill(2)+end print "Renaming %s to %s" % (file, newname+extension) elif os.path.isfile(file): newname = start+str(loops)+end print "Renaming %s to %s" % (file, newname+extension) loops+=1 check() print "Continue?: y/n" answer = raw_input() if answer == "y": rename() else: print "Exiting"