Skip to content

Instantly share code, notes, and snippets.

@johl
Created November 21, 2008 14:26
Show Gist options
  • Save johl/27440 to your computer and use it in GitHub Desktop.
Save johl/27440 to your computer and use it in GitHub Desktop.
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