import os.path
from datetime import datetime, timedelta


def delete_file_after_delay():
    path = "data/output"
    data_dir = os.path.dirname(path)
    if not os.path.exists(data_dir):
        return
    if not os.path.exists(path):
        return
    now = datetime.now()
    five_minutes_ago = now - timedelta(minutes=5)
    for filename in os.listdir(path):
        file_path = os.path.join(path, filename)
        if os.path.isfile(file_path):
            creation_time = os.path.getctime(file_path)
            file_creation_datetime = datetime.fromtimestamp(creation_time)
            if file_creation_datetime < five_minutes_ago:
                os.remove(file_path)
                print(f"定时删除文件: {file_path}")
