kipishio

Untitled

Dec 7th, 2021
499
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2.  
  3.  
  4. def gen_files(name_dir, dir):
  5.     path = dir
  6.     list_dir = os.listdir(path)
  7.  
  8.     for name in list_dir:
  9.  
  10.         if os.path.isfile(os.path.join(path, name)):
  11.             yield os.path.join(path, name)
  12.             # my_list.append(os.path.join(path, name))
  13.  
  14.         elif os.path.isdir(os.path.join(path, name)):
  15.             if name == name_dir:
  16.                 yield 'Искомый каталог: {}'.format(os.path.join(path, name))
  17.                 # my_list.append(os.path.join(path, name))
  18.                 return
  19.  
  20.             yield os.path.join(path, name)
  21.             # my_list.append(os.path.join(path, name))
  22.             gen_files(name_dir, os.path.join(path, name))
  23.  
  24.  
  25. path = os.path.abspath('../..')
  26. print('путь', path)
  27. my_list = []
  28.  
  29. for i in gen_files('Module26', path):
  30.     print(i)
  31.  
  32. # gen_files('Module26', path)
  33. # for i in my_list:
  34. #     print(i)
RAW Paste Data