Need help, I’m new to python,
I wrote a script that should find all files in a directory and process only ones that have a specific line and skip the ones that do not have the line. The specific line is ‘," Run Time’ it fails to process ONLY files I need, it processes all files.
All Lines to find:
‘," Run Time’
‘,” Start Time’
‘,” End Time’
‘Test_ID:’
‘Test Program Name:’
‘Product:’
Also,
Lines 1, 2 and 3 are repeating lines and I need them all,
Lines 4, 5 and 6 also repeating but I need to capture them only ones.
Here is the script I have:
I wrote a script that should find all files in a directory and process only ones that have a specific line and skip the ones that do not have the line. The specific line is ‘," Run Time’ it fails to process ONLY files I need, it processes all files.
All Lines to find:
‘," Run Time’
‘,” Start Time’
‘,” End Time’
‘Test_ID:’
‘Test Program Name:’
‘Product:’
Also,
Lines 1, 2 and 3 are repeating lines and I need them all,
Lines 4, 5 and 6 also repeating but I need to capture them only ones.
Here is the script I have:
Python:
import os
runtime_l = '," Run Time'
start_tm = '," Start Time'
end_tm = '," End Time'
test_ID = ' Host Name: '
program_n = 'Test Program Name:'
prod_n = 'Product:'
given_path = 'C:\\02\\en15\\TST'
for filename in os.listdir(given_path):
filepath = os.path.join(given_path, filename)
if os.path.isfile(filepath):
print("File Name: ", filename)
print("File Name\\Path:", filepath)
with open(filepath) as mfile:
for line in mfile:
if runtime_l in line:
# do something with the line
print(line)
if start_tm in line:
# do something with the line
print(line)
if end_tm in line:
# do something with the line
print(line)
if test_ID in line:
# do something with the line
print (line)
if program_n in line:
# do something with the line
print (line)
if prod_n in line:
# do something with the line
print (line)
else:
continue