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

Posted fengyiru6369

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\rv_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路径文件

以上是关于python之删除指定目录指定日期下的日志文件的主要内容,如果未能解决你的问题,请参考以下文章

linux 定时任务,压缩 日志,并删除掉 指定日期之前的 日志

python 按照日期切分大日志文件(重点)和按照指定大小切分日志文件

python根据文件更改日期删除指定文件夹下面文件

linux sed 之 查看指定时间段的日志

rsyslog传输指定目录下的全部日志数据

删除指定目录下过期文件并打印日志