Skip to content

Instantly share code, notes, and snippets.

@sudhakar6
Last active May 9, 2022 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudhakar6/073ddc9b5339daae841e3701c1fc7874 to your computer and use it in GitHub Desktop.
Save sudhakar6/073ddc9b5339daae841e3701c1fc7874 to your computer and use it in GitHub Desktop.
Python script to change the change files names in a directory(Windows, May work for Mac as well but not tested)
import os
path = r'C:\Users\SudhakaraReddy.Chint\Desktop\customMetadata\\'
files = os.listdir(path)
for index, file in enumerate(files):
print(file)
#To remove suffix of the file name, this can be replaced based on the requirement
filern = file.removesuffix('.md-meta.xml')
#To remove last three characters of the file name, this can also be modified.
filern = filern[:-3]
#To concatenate file name and file index in loop
filern = filern+str(index)+'.md-meta.xml'
print(filern)
print(file)
#To rename the file
os.rename(os.path.join(path, file), os.path.join(path, filern))
Example:
Input file name: Code_Config.GDPRLastActivity_Contact.md-meta.xml
Output file name: Code_Config.GDPRLastActivity_Cont127.md-meta.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment