import os
def catalog_search(path_to_catalog: str) -> list:
fl_lst = []
directory_ = os.walk(path_to_catalog, topdown=True)
for address, dirs, files in directory_:
for name in files:
fl_lst.append(os.path.join(address, name))
return fl_lst
def amount_file_string(list_: list) -> int:
for i_file in list_:
try:
with open(i_file, 'r') as f:
amount = f.readlines()
yield len(amount)
except FileNotFoundError:
print(f'Файл не найден: {i_file}')
catalog = 'L:\\28.Python\\Python_Basic\\Module14'
file_list = catalog_search(catalog)
file_strings = (amount_file_string(file) for file in file_list)
print(f'Найдено {len(file_list)} файлов в каталоге {catalog}.')
for i_value in file_strings:
try:
print(f'Количество строк в файле {i_value}')
except StopIteration:
pass
import os
def catalog_search(path_to_catalog: str) -> list[str]:
fl_lst = []
directory_ = os.walk(path_to_catalog, topdown=True)
for address, dirs, files in directory_:
for name in files:
fl_lst.append(os.path.join(address, name))
return fl_lst
def amount_file_string(list_: list[str]):
for i_file in list_:
try:
with open(i_file, 'r') as f:
amount = f.readlines()
yield len(amount)
except FileNotFoundError:
print(f'Файл не найден: {i_file}')
catalog = 'L:\\28.Python\\Python_Basic\\Module14'
file_list = catalog_search(catalog)
file_strings = (file_num for file_num in amount_file_string(file_list))
print(f'Найдено {len(file_list)} файлов в каталоге {catalog}.')
for i_value in file_strings:
try:
print(f'Количество строк в файле {i_value}')
except StopIteration:
pass