Sorry about the HTML mail -- here it is plain text.
If I understand the suggestions, to do this properly I should probably
be doing a Depth-First Search. Well, interestingly I need to do just
this for another tool which constructs a dependency tree based upon file
dependencies for a particular code.
I think the webchecker tool does something similar.
Before I try to write my own, I'd like to enquire about Python's
"batteries" -- is there a good built-in data structure to construct an
adjacency list of nodes that could be files or data sources?
Here's the other tool. It sounds like I might get away with adding to
the bottom of lister:
if os.path.isdir(path).isempty():
purge(path)
Except I'd have to loop through again ...?
Thanks for all the help!
"""Delete files older than AGING constant using os.path.walk"""
import sys, os, time
AGING = 172800 # Default 2 days
def lister(dummy, dirName, filesInDir):
print '[' + dirName + ']'
for fname in filesInDir:
path = os.path.join(dirName, fname)
if not os.path.isdir(path):
print path, time.ctime(os.stat(path).st_mtime),
fileage(path), prune(path)
purge(path)
def fileage(file):
curtime = time.time()
modtime = os.stat(file).st_mtime
age = curtime - modtime
return age
def prune(file):
if fileage(file) > AGING:
return ("T")
else:
return ("File should not be deleted")
def purge(file):
if prune(file) == "T":
os.remove(file)
if __name__ == '__main__':
os.path.walk(sys.argv[1], lister, None)
--Adam Getchell
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython