0
我寫了這個,但它不起作用。 在giorni
我把留在SD的最大天數和file_dir
是分析文件的默認位置。刪除Y文件夾中比X天早的每個文件
import os
from datetime import datetime, timedelta
file_dir = "/home/pi/" #location
giorni = 2 #n max of days
giorni_pass = datetime.now() - timedelta(giorni)
for root, dirs, files in os.walk(file_dir):
for file in files:
filetime = datetime.fromtimestamp(os.path.getctime(file))
if filetime > giorni_pass:
os.remove(file)