npm не работает после create-реагировать на приложение из-за модуля babel

Не рекурсивно

Чтобы получить файлы (и только файлы) каталога «path», с «globexpression»:

list_path = [i for i in os.listdir(path) if os.path.isfile(os.path.join(path, i))]
result = [os.path.join(path, j) for j in list_path if re.match(fnmatch.translate(globexpression), j, re.IGNORECASE)]

Рекурсивно

с прогулкой:

result = []
for root, dirs, files in os.walk(path, topdown=True):
  result += [os.path.join(root, j) for j in files \
             if re.match(fnmatch.translate(globexpression), j, re.IGNORECASE)]

Лучше также скомпилировать регулярное выражение, поэтому вместо

re.match(fnmatch.translate(globexpression)

выполните (перед циклом):

reg_expr = re.compile(fnmatch.translate(globexpression), re.IGNORECASE)

, а затем заменить в цикле:

  result += [os.path.join(root, j) for j in files if re.match(reg_expr, j)]
0
задан zackclan 27 February 2019 в 21:16
поделиться