52 lines
1022 B
Python
52 lines
1022 B
Python
#!/usr/bin/env python
|
|
|
|
import pathlib
|
|
from datetime import datetime
|
|
import glob
|
|
import time
|
|
import os
|
|
import sys
|
|
import shutil
|
|
|
|
days = sys.argv[1]
|
|
WatchedLocation = str(sys.argv[2])
|
|
|
|
|
|
if days.isnumeric():
|
|
print("true")
|
|
else:
|
|
print("shite")
|
|
exit(0)
|
|
|
|
ToLive = int(days) * int(86400)
|
|
|
|
print(ToLive)
|
|
def checkAgeOfFile(filename):
|
|
fname = pathlib.Path(filename)
|
|
# print(fname)
|
|
print(int(time.time()) - fname.stat()[-1:][0])
|
|
if (int(time.time()) - fname.stat()[-1:][0]) > ToLive:
|
|
return True
|
|
print("true")
|
|
else:
|
|
return False
|
|
print("false")
|
|
|
|
|
|
def deleteFilesNFolders(location):
|
|
if os.path.isdir(location):
|
|
print("This is a dir: " + location)
|
|
shutil.rmtree(location)
|
|
if os.path.isfile(location):
|
|
print("This is a file: " + location)
|
|
os.remove(location)
|
|
|
|
|
|
for x in glob.glob(WatchedLocation):
|
|
# print(x)
|
|
# print("poopy")
|
|
if checkAgeOfFile(x):
|
|
print("poop")
|
|
print(x)
|
|
deleteFilesNFolders(x)
|