Rename all files in a dir

This code will ask you what type of file do you want to rename and it will do it adding a progressive number to them.

import glob
import os

def rename(type_of_file)
	mp4 = glob.glob("*." + type_of_file)

	for v in mp4:
		os.rename(v, "file" + str(mp4.index(v)) + type_of_file)

t = input("Type of file to rename (mp4,txt...) > ")
rename(t)

 

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.