Skip to content

Instantly share code, notes, and snippets.

@tiiime
Created March 27, 2022 14:19
Show Gist options
  • Save tiiime/6b1316d3c74594ace557147549223600 to your computer and use it in GitHub Desktop.
Save tiiime/6b1316d3c74594ace557147549223600 to your computer and use it in GitHub Desktop.
import re
import os
folder = os.getcwd()
count = 1
# count increase by 1 in each iteration
# iterate all files from a directory
for file_name in os.listdir(folder):
# Construct old file name
source = folder + "\\" + file_name
# Adding the count to the new file name and extension
destination = folder + "\\" + re.sub(r'\[(\d+)\]', r'S01E\1', file_name)
# Renaming the file
os.rename(source, destination)
count += 1
print('All Files Renamed')
print('New Names are')
# verify the result
res = os.listdir(folder)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment