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

import os,random,time,shutil
list_dir = os.listdir(r"D:\test1")
for file in list_dir:
  print(file)
  print(os.path.abspath(file))
  os.chdir(r"D:\test1")
  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)

posted on 2019-04-03 14:29  SZ_文彬  阅读(95)  评论(0编辑  收藏  举报