import os, sys from typing import final # Getting the folder folder = '' if folder == '': folder = os.getcwd() folderChoice = input(f'The selected folder is \n{folder}\nProceed with the folder above? (Y/n): ') if folderChoice.lower() == 'n': folder = input('Enter path where you want to rename files:\n') elif folderChoice.upper() != 'Y': print('What am I supposed to do now?!!!') assert False # Getting all the files os.chdir(folder) print(f'Proceeding with {folder}') ls = os.listdir() files = [] folders = [] for item in ls: if os.path.isfile(item): files.append(item) else: print(f'WARNING: {item} is not a file!') # for file in files: print(file) files.sort() # print(f'\n{"="*30}') # for file in files: print(file) # Getting season def getSeason(folder): # print(f'folder: {folder}') # print(os.path.split(folder)[-1]) if os.path.split(folder)[-1] != '': # print('if is working') path = os.path.split(folder)[-1] # print(f'path: {path}') return path else: # print('else is working') # getSeason(os.path.split(folder)[-2]) # print(f'os.path.split(folder)[-2]: {os.path.split(folder)[-2]}') return getSeason(os.path.split(folder)[-2]) season = getSeason(folder) season = season[7:9] seasonConfirmation = input(f'The season seems to be: "{season}". Is it correct? (Y/n)? ') if seasonConfirmation.lower() == 'n': season = input('Please enter the season(Make it double digit, add a 0 in the front if needed): ') elif seasonConfirmation.upper() != 'Y': print('What do I do now?!!!') assert False print(f'Proceeding with season {season}') # Get new name string # f'{filename[:16]} test{filename[16:]}' def renameTo(filename, season, episode): return f'{filename[:16]} S{season}E{episode}{filename[16:]}' # Dry run print(f'\nThe files will be renamed like this:\n') renameInfo = [] episode = 1 for file in files: print(f'{file} => {renameTo(file, season, episode)}') episode += 1 finalConfirmation = input('Do you want to proceed with the changes listed above? (Y/n): ') # Final confirmation logic if finalConfirmation.lower() == 'n': print('got it, terminating') assert False elif finalConfirmation.upper() != 'Y': print('What do I do now? :\'(') assert False elif finalConfirmation.upper == 'Y': print('renaming files...') # Rename! episode = 1 for file in files: os.rename(file, renameTo(file, season, episode)) episode += 1 print(f'Renamed {file}')