作用:根据关键字检索文件内容,输出文件列表
代码:
xxxxxxxxxx
# 作者:常晓松
# 作用:根据关键字检索文件内容,输出文件列表
# 时间: 2023/6/20 21:28
import os
from sys import argv
def get_filelist(dir):
Filelist = []
for home, dirs, files in os.walk(path):
for filename in files:
# 文件名列表,包含完整路径
if filename.find("." + type) >= 0:
with open(os.path.join(home, filename), 'r', encoding='ISO-8859-1') as file:
line = file.readline()
while line:
if line.find(content) >= 0:
Filelist.append(os.path.join(home, filename))
break
line = file.readline()
return Filelist
if __name__ == "__main__":
path = "1D:\\GitHub-download-package\\新建文件夹" # 文件夹目录
type = "2ipynb"
content = "3LSTM"
if len(argv) == 4:
path = argv[1]
type = argv[2]
content = argv[3]
else:
print("参数错误")
exit(-1)
Filelist = get_filelist(dir)
for file in Filelist:
print(file)