import os file_path = input('Please enter the directory path you want to explore: ') target = input('please enter the key word you want to find: ') def file_location(file_path): #定义寻找目标文件夹内的后缀为'.txt'的文件 os.chdir(file_path) content_list = os.listdir(os.curdir) for each in content_list: if os.path.splitext(each)[1] == '.txt'
python针对指定目录内的文本文件的关键字搜索
最新推荐文章于 2023-10-26 15:57:52 发布
这个Python脚本允许用户输入一个目录路径和一个关键字,然后搜索该目录及其子目录下的所有.txt文件,找出包含关键字的文件,并打印出含有关键字的行号和字符位置。
摘要由CSDN通过智能技术生成