I have a given file I need to find within a folder structure. There can and will be duplicate filenames within the file structure so I also need to return the file with the closest modified date to a given date. Simply returning the most recent file as shown below will not fit my need. This is one of those questions where there is no way to google and possibly return anything helpful.
def findClosestFile(name, path, date):
result=[]
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
return max(result, key=os.path.getmtime))