Created
August 9, 2022 08:55
-
-
Save nermin99/4cc1ba6d974db1dae08869ac18d76af1 to your computer and use it in GitHub Desktop.
Batch rename exam names
This file contains hidden or 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 | |
# Batch rename all files on the form: | |
# exam_211028.pdf -> exam_2021-10-28.pdf | |
filePath = './Exams/' | |
for fileName in sorted(os.listdir(filePath)): | |
prefix, after = fileName.split('_') | |
date, ext = after.split('.') | |
newDate = '20' + '-'.join(date[i:i+2] for i in range(0, len(date), 2)) | |
newName = prefix + '_' + newDate + '.' + ext | |
# print(filePath + newName) | |
os.rename(filePath + fileName, filePath + newName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment