python - 遍历目录并获取信息表单文件名
问题描述
我有以下文件结构:
C:\file1:
->test1
-> 2021_08_18_16_45_09-jbkjjkbkuiuhi
-> LOG_2021_08_18_16_45_09.txt
-> 2021_09_09_14_35_39-hgkhbkbhkb
-> LOG_2021_09_09_14_35_39.txt
-> 2021_05_07_06_15_19-jkbkjbkjb
-> LOG_2021_05_07_06_15_19.txt
->test2
-> 2021_07_18_16_45_09-hbkbnnansa
-> LOG_2021_07_18_16_45_09.txt
->test3
-> 2021_06_19_11_25_29-hbjkhbj
-> LOG_2021_06_19_11_25_29.txt
-> 2021_03_08_12_41_01-jhbjhbbjkjbkj
-> LOG_2021_03_08_12_41_01.txt
每个 LOG 文件的结构如下:
...
...
2021_08_18_16_45_09 PASSED
wrere instaed of pass 也可以FAILED/ PASSED WITH WARNINGS
等等
我需要获取名称列表:
tests = ['test1', 'test2', 'test3']
和时间戳:
timestamps = [2021_08_18_16_45_09, 2021_09_09_14_35_39, 2021_05_07_06_15_19, 2021_07_18_16_45_09, 2021_06_19_11_25_29, 2021_03_08_12_41_01]
以及 LOG 文件的所有路径:
all_paths = [C:\file1\test1\2021_08_18_16_45_09-jbkjjkbkuiuhi\LOG_2021_08_18_16_45_09.txt, ...]
以及每个测试的结果(我的日志文件中存在的字符串之一PASSED/FAILED/ PASSED WITH WARNINGS
:)
问题是如何以最佳方式有效地获取此类数据?
解决方案
推荐阅读
- mocking - 如何在没有嵌入式服务器或新集群的情况下模拟 couchbase 以进行验收测试?
- angular-material - 单个模板中的材料角多表数据源 + 材料角多表“找不到具有 id 的列”
- go - Go 变量初始化语法
- java - 如何将多个 Spring Boot 应用程序合并为一个?
- java - 如何验证非必需的 RequestParam 不为空?
- javascript - 输入中的格式化数字反应
- sql - 选择中的条件语句
- reactjs - 使用 AsyncStorage 在 React Native 中执行 CRUD 操作
- summernote - 在其他事件上启动 Summernote Popover
- vb.net - 如何在启动时不在桌面上显示应用程序