hi again, if you remember i had been asking how to extend my music player to do two things:
1)play music from folders and subfolders (complete)
2)change song at the end of each one (incomplete)
well after looking around a while i found the answer :
# create a list of all the files in a given direcory
# and any of its subdirectories (Python25 & Python30)
import os
import os.path
def file_lister(currdir, mylist=[]):
"""
returns a list of all files in a directory and any of
its subdirectories
note that default mylist becomes static
"""
for file in os.listdir(currdir):
# add directory to filename
full_name = os.path.join(currdir, file)
if not os.path.isdir(full_name):
mylist.append(full_name)
else:
# recurse into subdirs
file_lister(full_name)
return mylist
which i edited and added to my program to make this:
import webbrowser, random
import os
import os.path
running = 1
def file_lister(currdir, mylist=[]):
"""
returns a list of all files in a directory and any of
its subdirectories
note that default mylist becomes static
"""
for file in os.listdir(currdir):
# add directory to filename
full_name = os.path.join(currdir, file)
if not os.path.isdir(full_name):
mylist.append(full_name)
else:
# recurse into subdirs
file_lister(full_name)
return mylist
dir_name = r"C:\Documents and Settings\Owner\My Documents\\"
file_lists = file_lister(dir_name)
file_list = filter(lambda x: x.lower().endswith(".mp3"),file_lister(dir_name))
choice = int(raw_input("Press 1 to play a new song"))
while running == 1:
if choice == 1:
song = random.choice(file_list)
webbrowser.open(os.path.join(dir_name,song))
choice = float(raw_input("Press 1 to play a new song"))
but now i want to make it fully automatic and change song at the end of the previous one, how would i go about this?