# 打开目录下所有以 .csv 结尾的文件,搜索特定的关键词 import os path = r'./' tot_file = 0 for root, dirs, files in os.walk(path): for file in files: if file.endswith('.csv'): if '2023-10' not in file: continue tot_file += 1 with open(os.path.join(root, file), 'r', encoding='utf-8') as f: for line in f: if '-2535,65,-746' in line: print(line, end='') print('Tot file:', tot_file)