My code iterates through the txt files in a folder and then extracts headers (the line containing "| SYS" and writes them to another file. However, when the file is not found the code simply fails without an error. E.g. it searches through files containing USR02, USR06, 1251 and TEXTS in file name. But when some file containing e.g. 1251 is not found it does not search for the next file containing "TEXTS". There is no error message. Any ideas?
from glob import glob
import fileinput
table02 = ('FINAL' + '\\'+ '0a_USR02.txt')
with open(table02, 'w') as out:
for line in fileinput.input(glob('*USR02.txt')):
if '| SYS' in line:
out.write(line)
table06 = ('FINAL' + '\\'+ '0a_USR06.txt')
with open(table06, 'w') as out:
for line in fileinput.input(glob('*USR06.txt')):
if '| SYS' in line:
out.write(line)
table09 = ('FINAL' + '\\'+ '0a_AGR_TEXTS.txt')
with open(table09, 'w') as out:
for line in fileinput.input(glob('*TEXTS.txt')):
if '| SYS' in line:
out.write(line)
table03 = ('FINAL' + '\\'+ '0a_AGR_1251.txt')
with open(table03, 'w') as out:
for line in fileinput.input(glob('1251.txt')):
if '| SYS' in line:
out.write(line)