import os
import os.path
import sys
arr= os.listdir()
arr.sort()
FO = open('Log_Out_Res.txt', 'w')
for file in arr:
if file.endswith('.res'):
fopen= open(file)
# loop throgh each line in the file till get the desired string and extract the version
for line in fopen:
lstrip = line.strip()
if lstrip.startswith('Test File Version:'):
try:
lsplit= lstrip.split()
print(file, "\n Test File Version:",lsplit[3])
FO.writelines(file + ':\n')
FO.writelines(lsplit[3])
FO.writelines('\n')
except:
break
if lstrip.startswith('Result File %version:'):
try:
linesplit= lstrip.split()
print(" Res File Version:",linesplit[3])
FO.writelines('Res File Version:'+linesplit[3])
FO.writelines('\n')
except:
break
最后,下面的代码达到了目的
相关问题 更多 >
编程相关推荐