If possible, avoid continue
because it hides the logical flow of the program.
import os
import re
def main():
path = r'C:\Python34\test'
listing = os.listdir(path)
for infile in listing:
with open(os.path.join(path, infile)) as data:
text = data.read()
match = re.search('(hi.*?)bye', text, re.DOTALL)
if match:
print('true')
print(match.group(1))
print('------------------------------------')
if __name__ == '__main__':
main()
Use os.path.join
to combine paths. Use with
to open files, so they are closed automatically.