Skip to content

Instantly share code, notes, and snippets.

@jvrplmlmn
Created October 3, 2013 09:04
Show Gist options
  • Select an option

  • Save jvrplmlmn/6807263 to your computer and use it in GitHub Desktop.

Select an option

Save jvrplmlmn/6807263 to your computer and use it in GitHub Desktop.
Purgate files older than the given days.
#!/usr/bin/env python
import os, time, sys, datetime
path = "/foo/bar"
days = 30
threshold = days * 86400
now = time.time()
timestamp = datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')
for f in os.listdir(path):
f_path = os.path.join(path, f)
if os.stat(f_path).st_mtime < now - threshold and os.path.isfile(f_path):
print "%s | Removing %s" % (timestamp, f_path)
os.remove(f_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment