import re, os

cesta=r"u:\Dropbox\!77242113UCO2001\#250 ECG\#010 Široký"



from openpyxl import Workbook
wb = Workbook()
ws = wb.active
# Add headers
ws.append(['Filename', 'Datetime'])


for file in os.listdir(cesta):
    filename = os.path.join(cesta, file)
    with open(filename,"rb") as f:
        nacteno=f.read()
        vyhledani=re.search(rb"202[3|4|5]-\d\d-\d\dT\d\d:\d\d:\d\d",nacteno)
        if vyhledani:
            print(file,vyhledani.group().decode("ASCII"))
            ws.append((file,vyhledani.group().decode("ASCII")))
        # print(len(nacteno))
wb.save(os.path.join(cesta,'output_openpyxl.xlsx'))

# filename=r"u:\Dropbox\!77242113UCO2001\#250 ECG\#010 Široký\0000003C.ECG"
#
# with open(filename,"rb") as f:
#     nacteno=f.read()
#     match=re.search(rb"202[3|4|5]-\d\d-\d\dT\d\d:\d\d:\d\d",nacteno)
#     if match:
#         print(match.group())
#         print(match.group().decode("ASCII"))