mike23415 commited on
Commit
fb6baa4
·
verified ·
1 Parent(s): 77bf716

Create cleanup.py

Browse files
Files changed (1) hide show
  1. cleanup.py +20 -0
cleanup.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+
4
+ FOLDER = "/tmp"
5
+ MAX_AGE_MINUTES = 60
6
+
7
+ def clean_old_files(folder=FOLDER, max_age=MAX_AGE_MINUTES):
8
+ now = time.time()
9
+ for f in os.listdir(folder):
10
+ path = os.path.join(folder, f)
11
+ if os.path.isfile(path):
12
+ if now - os.path.getmtime(path) > max_age * 60:
13
+ try:
14
+ os.remove(path)
15
+ print(f"[Cleanup] Deleted: {path}")
16
+ except Exception as e:
17
+ print(f"[Cleanup Error] {e}")
18
+
19
+ if __name__ == "__main__":
20
+ clean_old_files()