Old File Purge Suggestions?
Fredrik Lundh
fredrik at pythonware.com
Mon Mar 18 11:27:07 EST 2002
Chris Liechti wrote:
> > I'm using sys.stdin.readlines(): getting the date passed in from
> > from "ls -l" (linux). Then compare dates using the mxDateTime
>
> i think os.stat gives you the same information as "ls -l" and you
> don't have to parse strings (use os.listdir to get the names and then
> stat on them)
os.path.getmtime is a bit easier to use, e.g:
import time, os
now = time.time()
max_age = 3 * 86400 # three days
for file in os.listdir(directory):
fullname = os.path.join(directory, file)
if now - os.path.getmtime(fullname) > max_age:
print "remove", fullname
# os.remove(fullname)
</F>
More information about the Python-list
mailing list