# -*- coding:utf-8 -*- import os import datetime date = datetime.datetime.now()-datetime.timedelta(days=30) # print(date.strftime("%Y-%m-%d")) folder_path = "/home/user/EgoJC/EgoSystem/build/log/" if os.path.exists(folder_path): file_names = os.listdir(folder_path) for file_name in file_names: if date.strftime("%Y-%m-%d") > file_name[:10]: # print(folder_path+file_name) os.remove(folder_path+file_name)