# for multiple files import os for dirname in os.listdir("."): print((dirname[:-4]).zfill(6)+'.txt') os.rename(dirname, (dirname[:-4]).zfill(6)+'.txt')