All pastes #2007468 Raw Edit

Batch video file renamer

public python v1 · immutable
#2007468 ·published 2010-12-01 06:30 UTC
rendered paste body
import osexts = [".264", ".mkv", ".mp4", ".mpeg", ".mpg", ".mov", ".avi", ".wmv", ".idx", ".sub", ".srt"]splitdir = os.getcwd().split("\\") #return array of the current working director, split by foldersnameinfo = splitdir[-2:] #make new array with last two elements of splitdirif int(nameinfo[1]) < 10 and len(nameinfo[1]) < 2:	start = nameinfo[0]+".S"+nameinfo[1].zfill(2)+"E"else:	start = nameinfo[0]+".S"+nameinfo[1]+"E"end = ".HDTV.XviD-2HD"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]			if extension in exts:				if loops < 10:					newname = start+str(loops).zfill(2)+end					os.rename(file, newname+extension)				elif os.path.isfile(file):					newname = start+str(loops)+end					os.rename(file, newname+extension)				loops+=1def 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+=1check()print "Continue?: y/n"answer = raw_input()if answer == "y":	rename()else:	print "Exiting"