Skip to content

Instantly share code, notes, and snippets.

@nermin99
Created August 9, 2022 08:55
Show Gist options
  • Save nermin99/4cc1ba6d974db1dae08869ac18d76af1 to your computer and use it in GitHub Desktop.
Save nermin99/4cc1ba6d974db1dae08869ac18d76af1 to your computer and use it in GitHub Desktop.
Batch rename exam names
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