Created
December 8, 2013 13:28
-
-
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.
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 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