Ok, here's the scenerio: I'm making a Windows 7 program that searches for all the music files in a directory and checks the user's input against that list so it can play the song that the user selects. Because the tracks' names are often numbered like this for example: '01 name.mp3', I want to remove the '01' part from a new list and have the program record the '01', so it can recognize it from the new list and launch the file. In other words, I want the program to make a new list of filenames without the numbers, and let the program recognize the file and launch it by also knowing the number. Is this possible? (Tell me if this doesn't make any sense.) Also, Here is some of my code:
def GetMediaFName(source, name):
for key, val in source.iteritems():
if val == name:
return key
newList = {}
media_list = []
for dirpath, dirnames, filenames in os.walk(music_dir) and os.walk(alt_music_dir1):
for filename in [f for f in filenames if f.endswith(".m4a") or f.endswith(".mp3") or f.endswith(".mp4")]:
media_list.append(os.path.join(dirpath, filename))
media_from_menu = menu[5:]
print(media_from_menu)
media_to_search1 = media_from_menu + ".mp3"
media_to_search2 = media_from_menu + ".wav"
media_to_search3 = media_from_menu + ".m4a"
media_to_search4 = media_from_menu + ".mp4"
for i in media_list:
spl = i.split('\\')[-1]
if spl is not None:
try:
tmp = re.findall(r'\d+',spl.split('.')[0][0])
newList.update({i:i.replace(tmp,"").strip()})
except Exception:
newList.update({i:spl})
itms = newList.keys()
for i in files:
tmp = re.findall(r'\d+',i.split('.')[0][0])
newList.update({i:i.replace(tmp,"").strip()})
print(newList)
print(GetMediaFName(newList, media_from_menu + ".mp3"))