检查xml文件

#coding=utf-8
import os
import time
def verify(filePath):
    print("verify--" + filePath)
    list1=[]
    # filePath=str(log)+'\n'

    for f in open(filePath, 'r',encoding = 'utf-8'):
        list1+=str(f)
    A = 'com.example.gcloudu3ddemo'  # 检查对比的字符串
    B=0
    C=25
    log=''
    for verify in list1:
        verify = "".join(list1[B:C])
        if verify == A:
            log += filePath +"======"+ A+"\n"
            B += 1
            C += 1


        else:
            B+=1
            C+=1
    return log
    #verify.close()




def wj(maindir):
    log = ""
    pathdir = os.listdir(maindir)
    for a in pathdir:
        nwudir = os.path.join(maindir,a)  # 路径拼接
        if os.path.isfile(nwudir):  # 是否文件
            if os.path.splitext(nwudir)[1]=='.xml':  #是否xml
                if  nwudir == 'mars_share_sdk.xml':  # 剔除加密xml
                    pass
                elif nwudir == '\AndroidManifest.xml':
                    pass
           

                else:
                    log += verify(nwudir) + "\n"



        else:
            log += wj(nwudir) + "\n"
    return log

maindir='E:\\test'
log = wj(maindir)
now = time.strftime("%Y-%m-%d-%H_%M_%S",time.localtime(time.time()))  # 创建文件名
fp = open("E:\\"+now+r"log.txt", 'a')  # 新建log
fp.write(log.strip())  # 去除空格
fp.close()  # 关闭log

 

posted @ 2018-12-14 14:43  sin涛涛  阅读(938)  评论(0编辑  收藏  举报