So I'm writing a python script that will clean file names of useless and unwanted characters, but I'm running into a problem, I can't seem to figure out how to return a list or dictionary with all of the items in it that I iterated over. it only returns the first item I iterated over. this is my first time writing in python. any help would be greatly appreciated. I'm mostly writing this to learn. the clean_title() method is the one I'm trying to return from. and I call it at the bottom.
import os
import re
# here is how all my video files will look after this
# show name Season 1 Episode 1
filename = os.listdir("E:/Videos/TV/tv-show")
def clean_title(filename):
name = {}
for title in filename:
n_title = title.split('.')
index = [i for i, item in enumerate(n_title) if re.search('\w\d{2}\w\d{2}', item)]
if len(index) > 0:
name = {'title':n_title[0:index[0]], 'ep_info':n_title[index[0]]}
return name
def get_show_name(filename):
pass
def update_title():
#show_title = get_show_name + ' ' + get_episode_info
#print show_title
if __name__=="__main__":
test = clean_title(filename)
print test