import os
# Absolute path of a file
old_name = r"E:demosfiles
eportsdetails.txt"
new_name = r"E:demosfiles
eports
ew_details.txt"
# Renaming the file
os.rename(old_name, new_name)
# for multiple files
import os
for dirname in os.listdir("."):
print((dirname[:-4]).zfill(6)+'.txt')
os.rename(dirname, (dirname[:-4]).zfill(6)+'.txt')