Read files with only specific names from Amazon S3
There are several ways to do this in Python. For example, checking if 'stringA' is in 'stringB':
list1=['test-eob/PROCESSED_BY/FILE_JSON/222-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/1212121-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/122-multi.json',
'test-eob/PROCESSED_BY/FILE_JSON/qwqwq-Account.json',
'test-eob/PROCESSED_BY/FILE_JSON/wqwqw-multi.json',]
for i in list1:
if 'Account' in i:
print (i)
else:
pass
You can make use of a regex that matches your pattern from the list of objects.
import re
MATCH = "FILE_JSON/.*?Account.json"
full_list = [
"test-eob/PROCESSED_BY/FILE_JSON/222-Account.json",
"test-eob/PROCESSED_BY/FILE_JSON/1212121-Account.json",
"test-eob/PROCESSED_BY/FILE_JSON/122-multi.json",
"test-eob/PROCESSED_BY/FILE_JSON/qwqwq-Account.json",
"test-eob/PROCESSED_BY/FILE_JSON/wqwqw-multi.json"
]
for item in full_list:
if re.search(MATCH, item):
print(item)