File size: 560 Bytes
fb6baa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import time

FOLDER = "/tmp"
MAX_AGE_MINUTES = 60

def clean_old_files(folder=FOLDER, max_age=MAX_AGE_MINUTES):
    now = time.time()
    for f in os.listdir(folder):
        path = os.path.join(folder, f)
        if os.path.isfile(path):
            if now - os.path.getmtime(path) > max_age * 60:
                try:
                    os.remove(path)
                    print(f"[Cleanup] Deleted: {path}")
                except Exception as e:
                    print(f"[Cleanup Error] {e}")

if __name__ == "__main__":
    clean_old_files()