Created
March 27, 2022 14:19
-
-
Save tiiime/6b1316d3c74594ace557147549223600 to your computer and use it in GitHub Desktop.
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 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