I could not find similar question here but how can i rename using python any .xlsx file in a directory? The goal is not to hardcode the filename to rename it into something else. Any input or advice is much appreciated. Thank you very much.
What I have tried so far. What it does is, it creates another excel file but i just need the .xlsx in C:\Test to be rename as Master.xlsx.
for root, dirs, files in os.walk("C:\Test", topdown=False,):
for name in files:
base_name, ext = os.path.splitext(name) #Split name, extension
if ext in ".xlsx":
df = pd.read_excel(os.path.join(root, name))
df.to_excel(os.path.join(root, 'Master.xlsx'), index=False)