Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created December 8, 2013 13:28
Show Gist options
  • Save hideshi/7857509 to your computer and use it in GitHub Desktop.
Save hideshi/7857509 to your computer and use it in GitHub Desktop.
If you want to delete file which was passed for certain days since it was modified last time, you can use this script.
import sys
import datetime
import os
# Get arguments without file name.
args = sys.argv[1:]
# Get current date time.
now = datetime.date.today()
for i in args:
# Get absolute path by file name.
path = os.path.abspath(i)
# If file name contains '.log'.
if path.find('.log') > -1:
# Get last updated date time by file.
mtime = datetime.date.fromtimestamp(int(os.path.getmtime(path)))
# Delete if 14 days passed since the file had been modified.
if (now - mtime).days >= 14:
os.remove(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment