python版本为:2.7

import os
import sys
import time # Sets how many days old files are deleted
DAYS_N = 7
# To delete the path and the following subfiles
PATH = r'C:\inetpub\logs\LogFiles' def deletefile(PATH):
for eachfile in os.listdir(PATH):
filename = os.path.join(PATH, eachfile)
if os.path.isfile(filename):
lastmodifytime = os.stat(filename).st_mtime
# Sets how many days old files are deleted
endfiletime = time.time() - 3600 * 24 * DAYS_N
if endfiletime > lastmodifytime:
# To remove the following comment is to delete the.log suffix file
# Comment is delete path under all files do not match
if filename[-4:] == ".log":
os.remove(filename)
print "del %s success!!!" % filename
# If it is a directory, the current function is called recursively
elif os.path.isdir(filename):
deletefile(filename) if __name__ == '__main__':
deletefile(PATH) time.sleep(1)
print ('Deleting completed,success')

  

最新文章

  1. php通过判断来源主机头进行防盗链
  2. JS事件-让网页交互
  3. JavaScript正则表达式小记
  4. codeforces 486B.OR in Matrix 解题报告
  5. poj1979
  6. 《DDNS服务器的搭建和案例解决方法》
  7. [Oracle AR]Territory Flexfield
  8. HDU4521+线段树+dp
  9. weblogic 12c 配置jvm的内存大小
  10. 原生JS写Ajax的请求函数
  11. Android 网络框架--Retrofit
  12. JQ 替换节点
  13. 在C语言中基本数据类型所占的字节数
  14. CDN页面刷新接口定义[高升]
  15. Unity3d导出场景地图寻路
  16. June 5. 2018 Week 23rd Tuesday
  17. MT【248】$f(x)=\dfrac{1}{x-1}+\dfrac{1}{x-b}$的性质
  18. 检测浏览器(BOM)以及地址栏网址的API
  19. python脚本参数传递
  20. list页面-按照choice筛选丶传condition过滤筛选项丶筛选与显示同步

热门文章

  1. spring cloud 2.x版本 Eureka Server服务注册中心教程
  2. 宋宝华:关于Ftrace的一个完整案例
  3. 学习笔记56_WebServices
  4. CSPS模拟 96
  5. Python基本数据结构之字典
  6. 期末考试(正解:三分单峰函数 me~)
  7. linux 相关指令
  8. html5自动横屏的方法
  9. C#同级catch块和finally块中全都抛出异常,上一级捕获哪一个?
  10. IP网段的判断