Jan-14-2018, 07:33 AM
If you want to use glob library there is no need to use os.path.splitext to get the extension:
import glob import sys extensions = ('mp3', 'avi', 'mp4', 'mkv'] def find_media_files(path, files): result = [] for ext in files: pattern = path + '/*.' + ext # this will become /path/*.mp3 to search for. found = glob.glob(pattern) result.extend(found) return result my_collection = find_media_files(sys.argv[1], extensions) for file_ in my_collection: print(file_)