#!/usr/bin/python
#encoding:utf-8
#Filename: delete_xjlog.py
import os
import datetime
import time
import re

path=myPath

def dellog(filePath):
    '''Function: delete tomcat path logs.'''

    #print filePath
    today = datetime.date.today()
    month_ago = str(today - datetime.timedelta(days=30))        #获取一个月前的日期,日期格式1
    timeArray = time.strptime(month_ago, "%Y-%m-%d")            #转换时间数组
    #timestamp = int(time.mktime(timeArray))            #时间戳
    m_a2 = time.strftime("%Y%m%d", timeArray)           #日期格式2

    for eachFile in os.listdir(filePath):
        if re.findall(month_ago, eachFile) or re.findall(m_a2, eachFile):
            os.remove(filePath+"/"+eachFile)
            #print "delete OK."


for file in os.listdir(path):
    if os.path.isdir(path+"/"+file):
        #print file, "is a mulu"
        if re.findall(r'tomcat', file):
            #print path+"/"+file, "is I want mulu."
            dellog(path+"/"+file+"/logs")