fix autoremover #3
parent
fccc2a59fa
commit
4e5bbaefb8
|
@ -1,4 +1,4 @@
|
||||||
import os, datetime
|
import os, datetime, shutil
|
||||||
from pathlib import Path
|
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)
|
older_date = today_date - datetime.timedelta(days=keep_days)
|
||||||
last_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)
|
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():
|
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
|
return
|
||||||
elif last_date.month > older_date.month and Path(folder_path_month_creator(date=older_date, default_path=root_path)).exists():
|
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
|
return
|
||||||
elif os.path.exists(file_path_creator(date=older_date, default_path=root_path)):
|
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))
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue