I am trying to find if a given file pattern is available in a directory. If found, I would want to open and load as JSON. If not found, I would like to send an email saying that the file is not present.
File name: test_09082021.txt
import os
path ='/dev/stage/'
file_pattern = 'test*'
file = path + file_pattern
if os.path.isfile(file):
with open(file) as f:
data = json.load(f)
else:
mailserver.sendmail('abc@gmail.com','def@gmail.com',msg.as_string())
But the application couldn't find the file and is returning false in the IF statement.
Could you please advise how I can check for the file pattern to make this work?