定时删除日志

import os,time,shutil
root=r'D:\pylx\20210622'
while True:
    for item in os.listdir(root):
        abs_path = os.path.join(root, item)
        if time.time()-os.path.getctime(abs_path)>3600*24*3:
            if os.path.isfile(abs_path):
                os.remove(abs_path)
            else:
                shutil.rmtree(abs_path)
    time.sleep(3600*24)

  

posted @ 2021-06-25 14:36  小蕊-zr  阅读(30)  评论(0编辑  收藏  举报