1 from xlwt import * 2 import os 3 #------------------读数据--------------------------------- 4 #判断是否存在有此类型的文件且文件名一致 5 #---mrs_vgw--- 6 fileName_mrs_vgw_3 = "ubp_mrs_vgw日志error扫描结果.txt" 7 fileName_mrs_vgw_2 = "mrs_vgw日志摄像头注册记录.txt" 8 fileName_mrs_vgw_1 = "mrs_vgw进程CPU和内存使用率文件.txt" 9 #---mrs_rec_man--- 10 fileName_mrs_rec_man_1 = "mrs_rec_man进程CPU和内存使用率文件.txt" 11 fileName_mrs_rec_man_2 = "ubp_mrs_rec_man日志error扫描结果.txt" 12 fileName_mrs_rec_man_3 = "ubp_mrs_rec_man日志扫描结果.txt" 13 #---mrs_rec_sinker--- 14 fileName_mrs_rec_sinker_1 = "mrs_rec_sinker进程CPU和内存使用率文件.txt" 15 fileName_mrs_rec_sinker_2 = "ubp_mrs_rec_sinker日志error扫描结果.txt" 16 fileName_mrs_rec_sinker_3 = "ubp_mrs_rec_sinker日志扫描结果.txt" 17 #---文件名字列表--- 18 filenames = []#创建空列表的名字集合 19 filenames.append(fileName_mrs_vgw_1) 20 filenames.append(fileName_mrs_vgw_2) 21 filenames.append(fileName_mrs_vgw_3) 22 filenames.append(fileName_mrs_rec_sinker_1) 23 filenames.append(fileName_mrs_rec_sinker_2) 24 filenames.append(fileName_mrs_rec_sinker_3) 25 filenames.append(fileName_mrs_rec_man_1) 26 filenames.append(fileName_mrs_rec_man_2) 27 filenames.append(fileName_mrs_rec_man_3) 28 29 data_list = []#汇总数据列表 30 31 for name in filenames: 32 filePath = "D:\日志巡检存放路径" 33 os.chdir(filePath) 34 path = os.getcwd() 35 if os.path.exists(name): 36 file_only_open = open(name, "r") 37 if name == fileName_mrs_rec_man_1: 38 lines = file_only_open.readlines() 39 data_list.append(fileName_mrs_rec_man_1.strip("文件.txt") + ':' + '\n') 40 for line in lines: 41 data_list.append(line) 42 data_list.append('\n') 43 if name == fileName_mrs_rec_sinker_1: 44 lines = file_only_open.readlines() 45 data_list.append(fileName_mrs_rec_sinker_1.strip("文件.txt") + ':' + '\n') 46 for line in lines: 47 data_list.append(line) 48 data_list.append('\n') 49 if name == fileName_mrs_vgw_1: 50 lines = file_only_open.readlines() 51 data_list.append(fileName_mrs_vgw_1.strip("文件.txt") + ':' + '\n') 52 for line in lines: 53 data_list.append(line) 54 data_list.append('\n') 55 if name == fileName_mrs_rec_man_3: 56 lines = file_only_open.readlines() 57 data_list.append(fileName_mrs_rec_man_3.strip("文件.txt") + ':' + '\n') 58 for line in lines: 59 data_list.append(line) 60 data_list.append('\n') 61 else: 62 print("没有找到此文件:" + name) 63 64 # 文件读写方式是追加 65 file_new = open("MRS巡检报告手填数据汇总.txt", "w+") 66 for data in data_list: 67 file_new.writelines(str(data)) 68 file_new.close()