Skip to content

Instantly share code, notes, and snippets.

@h3nryza
Created July 18, 2018 08:15
Show Gist options
  • Save h3nryza/13003fd58ce66a97e5d08337ebf74c56 to your computer and use it in GitHub Desktop.
Save h3nryza/13003fd58ce66a97e5d08337ebf74c56 to your computer and use it in GitHub Desktop.
Python Dlete a file older than x
#!/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