Created
July 18, 2018 08:15
-
-
Save h3nryza/13003fd58ce66a97e5d08337ebf74c56 to your computer and use it in GitHub Desktop.
Python Dlete a file older than x
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/python | |
# -*- coding: <utf-8> -*- | |
from __future__ import print_function | |
import os | |
import time | |
current_time = time.time() | |
for file in os.listdir(): | |
creation_time = os.path.getctime(file) | |
if (current_time - creation_time) // (24 * 3600) >= 7: | |
os.unlink(file) | |
print('{} removed'.format(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment