[Tutor] operate on files based on comparing filenames to today's date

Matthew Herzog matthew.herzog at gmail.com
Thu Mar 28 12:08:05 EDT 2019


I have cobbled together this code which gives me regex matches of files
whose names either begin with either YYYYMMDD_? or erased_YYMMDD_? and
whose extensions are exml or ewav.
Now I need to compare the date string (regex match) in the filename to
today's date. If the result of the comparison results in YYYMMDD being
older than 180 days, I should print something to indicate this. If not,
nothing need be done.
Should I write another function to compare each matched regex to today's
date or is that overkill? Thanks.

todaystring = date.today().strftime("%Y%m%d")
oldest = date.today() - timedelta(days=180)
def get_files(extensions):
    all_files = []
    for ext in extensions:
        all_files.extend(Path('/Users/msh/Python/calls').glob(ext))
        return all_files
for file in get_files(('*.ewav', '*.exml')):
    print(re.match("[0-9]{8}|erased_",file.name))

-- 
The plural of anecdote is not "data."


More information about the Tutor mailing list