I have a folder where a set of two new different CSV files with different names are created daily, and I need to get the dates of the latest two created each day to verify if the dates correspond to the day previous.
Im currently using a code that I got to set up searching through several other posts but I'm getting a error that states:
AttributeError: 'list' object has no attribute 'date'
import os
import glob
import time
from datetime import datetime
import datetime as dt
from pathlib import Path
from datetime import timedelta
yesterday = (datetime.today() - timedelta(days=1)).date()
print('yesterdays date:', yesterday)
def test_modified(filename):
delta = time.time() - os.path.getmtime(filename)
delta = delta / (60*60*24)
if delta < 1:
return True
return False
path='C:\\testfolder\\'
for file in mfiles:
filetime = [mfile for mfile in glob.glob(path+'*.csv') if test_modified(mfile)]
if filetime.date() == yesterday:
print('The file has yesterdays date')
else:
print('The files doesnt have yesterdays date')
My guess is that I must include a Date attribute with the filetime list, but I don't know how.
Any help would be greatly appreciated!