i have a lop of video file and rename them so they look better e.g "show name s01e01" rather than "showname.s01e01.ggeeewg.mp4" so i created a program that could do it quicker than doing it by hand. code below
import os
import fnmatch
import time
file_path = 'C:\\Users\\Selene\\Videos\\Foundation\\Season 1 - Copy\\'
files_to_rename = fnmatch.filter(os.listdir(file_path), '*')
def season1():
chose = input(" 1 for quality removed, 2 for . removed, 3 for .mkv, 4 for capital S")
if chose == "1":
season1_1()
elif chose == "2":
season1_2()
elif chose == "3":
season1_3()
elif chose == "4":
season1_4()
def season1_1():
for file_name in files_to_rename:
os.rename(file_path + file_name, file_path + file_name.replace('.2160p.ATVP.WEB-DL.DDP5.1.HDR.HEVC-CasStudio', ''))
print("done")
season1()
def season1_2():
for file_name in files_to_rename:
os.rename(file_path + file_name, file_path + file_name.replace('.', ' '))
season1()
def season1_3():
for file_name in files_to_rename:
os.rename(file_path + file_name, file_path + file_name.replace(' mkv', '.mkv'))
season1()
def season1_4():
for file_name in files_to_rename:
os.rename(file_path + file_name, file_path + file_name.replace('s01e', 'S05E'))
season1()
season1()
But after i do the first rename i get the error "The system cannot find the file specified. i think this is because the loaded file list is no longer the same but i could be wrong. how do i fix this error do i need to reload the directory. Error code below
Traceback (most recent call last):
File "C:\Users\Selene\Documents\FileRename\main.py", line 41, in <module>
season1()
File "C:\Users\Selene\Documents\FileRename\main.py", line 11, in season1
season1_1()
File "C:\Users\Selene\Documents\FileRename\main.py", line 23, in season1_1
season1()
File "C:\Users\Selene\Documents\FileRename\main.py", line 13, in season1
season1_2()
File "C:\Users\Selene\Documents\FileRename\main.py", line 27, in season1_2
os.rename(file_path + file_name, file_path + file_name.replace('.', ' '))
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\Selene\\Videos\\Foundation\\Season 1 - Copy\\Foundation.S01E01.The.Emperors.Peace.2160p.ATVP.WEB-DL.DDP5.1.HDR.HEVC-CasStudio.mkv' -> 'C:\\Users\\Selene\\Videos\\Foundation\\Season 1 - Copy\\Foundation S01E01 The Emperors Peace 2160p ATVP WEB-DL DDP5 1 HDR HEVC-CasStudio mkv'