Last active
May 9, 2022 07:25
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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