deleting unaccessed files using python
- by damon
My django app parses some files uploaded by the user.It is possible that the file uploaded by the user may remain in the server for a long time ,without it being parsed by the app.This can increase in size if a lot of users upload a lot of files.
I need to delete those files not recently parsed by the app -say not accessed for last 24 hours.I tried like this
import os
import time
dirname = MEDIA_ROOT+my_folder
filenames = os.listdir(dirname)
filenames = [os.path.join(dirname,filename) for filename in filenames]
for filename in filenames:
last_access = os.stat(filename).st_atime #secs since epoch
rtime = time.asctime(time.localtime(last_access))
print filename+'----'+rtime
This shows the last accessed times for each file..But I am not sure how I can test if the file access time was within the last 24 hours..Can somebody help me out?