fix autoremover #3

main
Jan Beníček 2024-06-21 07:05:28 +02:00
parent fccc2a59fa
commit 4e5bbaefb8
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import os, datetime
import os, datetime, shutil
from pathlib import Path
@ -16,18 +16,18 @@ def remove_old_files(today_date: datetime.datetime, keep_days: int, root_path: s
older_date = today_date - datetime.timedelta(days=keep_days)
last_date = today_date - datetime.timedelta(days=keep_days)
while older_date > older_date - datetime.timedelta(days=10):
while older_date > (datetime.datetime.now() - datetime.timedelta(days=10 + keep_days)):
older_date = older_date - datetime.timedelta(days=1)
if last_date.year > older_date.year and Path(folder_path_year_creator(date=older_date, default_path=root_path)).exists():
Path(folder_path_year_creator(date=older_date, default_path=root_path)).rmdir()
shutil.rmtree(folder_path_year_creator(date=older_date, default_path=root_path))
return
elif last_date.month > older_date.month and Path(folder_path_month_creator(date=older_date, default_path=root_path)).exists():
Path(folder_path_month_creator(date=older_date, default_path=root_path)).rmdir()
shutil.rmtree(folder_path_month_creator(date=older_date, default_path=root_path))
return
elif os.path.exists(file_path_creator(date=older_date, default_path=root_path)):
os.remove(file_path_creator(date=older_date, default_path=root_path))
last_date = older_date
last_date = datetime.datetime(year=older_date.year, month=older_date.month, day=older_date.day)