import os,time,shutil root=r'D:pylx20210622' 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)