import os import glob files = glob.glob(".format1") for f in files: if not os.path.isdir(f): file_name = os.path.splitext(f) try: os.rename(f,filename[0] + '.format2') except: pass