• python之删除指定目录指定日期下的日志文件


    #=======================================================================================20190521以下脚本是通过读取excle路径删除应路进下的日志==============================================================
    # -*- coding:utf-8 -*-
    # ! /usr/bin/python
    # defaultencoding = 'utf-8'

    #
    # import datetime
    # import glob
    # import time
    # import os
    # import xlrd
    # import xlwt
    # from xlutils.copy import copy
    #
    # time1 = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
    # # today = datetime.date.today()
    # # print(today)
    # # time3 = datetime.date.today() - datetime.timedelta(days=1)
    # # time2 = time3.strftime("%Y%m%d")
    # # print( "time2=", time2)
    #
    #
    # def rm_log(path):
    # for n in range(1,31):
    # time3 = datetime.date.today() - datetime.timedelta(days=n)
    # time2 = time3.strftime("%Y%m%d")
    # F1 = glob.glob(path + r"*" + str(time2) + "*")
    # F2 = glob.glob(path + r"*" + ".txt")
    # for f1 in F1:
    # for f2 in F2:
    # if f1 == f2:
    # print("f1=", f1)
    # if (os.path.exists(f1)):
    # print("要删除对应路径下文件是", f1)
    # os.remove(f1)
    #
    #
    # data = xlrd.open_workbook(unicode(r"rv_log.xls",'utf-8')) # 读取路径文件,注意python2需要对中文路径加对应的编码格式
    # #data = xlrd.open_workbook(r"E:*******项目文件每周发布服务汇总20190419 v_log.xls",'utf-8')
    # table = data.sheet_by_index(0)
    # nrows = table.nrows #
    #
    # wbook = copy(data)
    # wsheet = wbook.get_sheet(0)
    # # 为了写入excle的格式为日期格式
    # dateFormat = xlwt.XFStyle()
    # dateFormat.num_format_str = 'yyyy/mm/dd'
    # j = 0;
    # for i in range(1, nrows):
    # # 获取第7列单元格的信息
    # rowValues = table.cell(i, 1).value # 从第0行开始数起
    # print( rowValues)
    # rm_log(rowValues)







    #=======================================================================================20190521==============================================================

    注意需要在指定目录上文件夹上面设置对应的excle路径文件
  • 相关阅读:
    idea html,js修改不用重启进程
    opencv rtsp 人脸识别
    The system is running in low-graphics mode UB16
    阿里云ecs 增加虚拟网卡
    rtsp
    mysql5.7报err 1055错误 sql_mode=only_full_group_by
    python 生成requirements.txt
    Linux 保护文件 不给修改
    logback logback.xml常用配置详解(三) <filter>
    logback 常用配置详解(二) <appender>
  • 原文地址:https://www.cnblogs.com/fengyiru6369/p/10901536.html
Copyright © 2020-2023  润新知