I have written this code
import os
from datetime import datetime
import re
now = datetime.now()
filename = now.strftime("%Y%m%d%H%M") #For example 202006191839
for fname in os.listdir(downloadPath):
if re.match('export_' + filename + '[0-9]{2}.xlsx', fname):
print(fname)
In downloadPath I have these files
- export_20200619183900.xlsx
- export_20200619183921.xlsx
- export_20200619183930.xlsx
But the re.match is not matching as desired.
But, if i change
filename = now.strftime("%Y%m%d%H%M")
with a simple assignment
filename = "202006191839"
The code works. The problem is, I need to have dynamic data.
Can anyone help me?