以下是示例代码:

import os

# 获取当前目录下的所有文件
files = os.listdir()

# 遍历文件列表,找到文件名中包含关键字的文件
for file in files:
    if 'BIT_log' in file and '.log' in file:
        # 打开文件并读取内容
        with open(file, 'r') as f:
            content = f.read()
            print(content)

该代码会先获取当前目录下的所有文件,然后遍历文件列表查找文件名中包含关键字'BIT_log'和'.log'的文件。如果找到了符合条件的文件,就打开文件并读取其中的内容,最后打印出来。

Python 代码:查找并读取包含 'BIT_log' 和 '.log' 的文件

原文地址: https://www.cveoy.top/t/topic/nVpe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录