Created
November 21, 2008 14:26
-
-
Save johl/27440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
from time import gmtime, strftime | |
from stat import * | |
def walktree(top, callback): | |
for f in os.listdir(top): | |
pathname = os.path.join(top, f) | |
mode = os.stat(pathname)[ST_MODE] | |
if S_ISDIR(mode): | |
# It's a directory, recurse into it | |
walktree(pathname, callback) | |
elif S_ISREG(mode): | |
# It's a file, call the callback function | |
callback(pathname) | |
else: | |
# Unknown file type, print a message | |
print 'Skipping %s' % pathname | |
def oldfiles(file): | |
now = gmtime() | |
then = gmtime(os.stat(file)[ST_MTIME]) # magic | |
alike = lambda x,y: ((x[0] == y[0]) and (x[1] == y[1])) # more magic | |
if (not (alike(now, then))): | |
# Uncomment the following if you are sure you want to delete: | |
# os.remove(file) | |
# Otherwise, just print it: | |
print file | |
if __name__ == '__main__': | |
walktree(sys.argv[1], oldfiles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment