删除30天没有访问过的日志

import os,random,time,shutil
list_dir = os.listdir(r"D: est1")
for file in list_dir:
  print(file)
  print(os.path.abspath(file))
  os.chdir(r"D: est1")
  file_time=os.stat(file).st_atime
  print(file_time)
  print(time.time())
  print(time.time()-file_time)

  if time.time()-file_time>2592000:
  print("TTTTT")
  if os.path.isdir(file):
  shutil.rmtree(os.path.abspath(file))
  else:
  os.remove(file)

原文地址:https://www.cnblogs.com/leiwenbin627/p/10648598.html