Created
October 3, 2013 09:04
-
-
Save jvrplmlmn/6807263 to your computer and use it in GitHub Desktop.
Purgate files older than the given days.
This file contains hidden or 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
| #!/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