import glob f = open("all.m3u", "w") for file in glob.iglob("/home/pi/radio_project/sounds/*"): f.write(file) f.write("\n") f.close()