import glob
from functools import reduce
from itertools import chain
def searchFiles(pathes:list, exts:list) -> list:
"""
searchFiles in pathes with target extention.
Ex) searchFiles(["/mnt/media1", "/mnt/usb/**/music], ["*.mp3", "*.jpg"])
case of extension is ignored.
return list of file path
"""
targetExts = [''.join(map(lambda c: '[%s%s]' % (
c.lower(), c.upper()) if c.isalpha() else c, ext)) for ext in exts]
targetPathes = [
dirPath + "/" + ext for dirPath in pathes for ext in targetExts]
foundFiles = map(lambda x: glob.iglob(x, recursive=True), targetPathes)
foundFiles = reduce(lambda a, b: chain(a, b), foundFiles) # Flatten
return foundFiles
コメントを残す