I am using below to remove files from disk.
def match_files(dir, pattern):
for dirname, subdirs, files in os.walk(dir):
for f in files:
if f.endswith(pattern):
yield os.path.join(dirname, f)
# Remove all files in the current dir matching *.txt
for f in match_files(dn, '.txt'):
os.remove(f)
What I would to remove files from disk that “was not updated today.” List the files from today. Check against to update list.
Besides
os.statyou could useos.path.getmtimeoros.path.getctime, the pro’s / con’s of which are discussed on this question. You can usedatetime.datetime.fromtimestampto convert the timestamp returned into adatetimeobject, and then you can do whatever you want. In this example I’ll remove files not modified today, create a list of remaining files: