Files
encoach_backend/app/helpers/io.py
Carlos Mesquita 3cf9fa5cba Async release
2024-07-23 08:40:35 +01:00

21 lines
691 B
Python

import datetime
import os
from pathlib import Path
class IOHelper:
@staticmethod
def delete_files_older_than_one_day(directory: str):
current_time = datetime.datetime.now()
for entry in os.scandir(directory):
if entry.is_file():
file_path = Path(entry)
file_name = file_path.name
file_modified_time = datetime.datetime.fromtimestamp(file_path.stat().st_mtime)
time_difference = current_time - file_modified_time
if time_difference.days > 1 and "placeholder" not in file_name:
file_path.unlink()
print(f"Deleted file: {file_path}")