我试图找到我的所有日志文件C:\,然后在这些日志文件中找到一个字符串。如果找到该字符串,则输出应该是找到该字符串的日志文件的 abs 路径。下面是我到目前为止所做的。
import os
rootdir=('C:\\')
for folder,dirs,file in os.walk(rootdir):
for files in file:
if files.endswith('.log'):
fullpath=open(os.path.join(folder,files),'r')
for line in fullpath.read():
if "saurabh" in line:
print(os.path.join(folder,files))
Run Code Online (Sandbox Code Playgroud)