读取xml文件内容,并完成不同后缀的文件的检验

import os
import shutil
import xml.etree.ElementTree as ET


path = "D:\\实习文件\\检验信息\\f"
newpath = ".\\false\\"

   
def png_or_xml(file):
    if file.endswith('png'):
        a=file.split(".")             
        new_file = a[0] + ".xml"
        return (new_file)
        
    else:
        file = os.path.join(path,file)
        e = ET.parse(file).getroot()
        for atype in e.findall('filename'):
            file = atype.text
            filename = file.split(".")
            new_file = filename[0] + ".png"
            return(new_file)
    
        

dirList = os.listdir(path)
for f in dirList:
    result = png_or_xml(f)
    file = os.path.join(path,result) 
    if os.path.exists(file):  
        print("right")  
    else:  
        print("Error" )
        print(f)
        a,b=f.split(".")             
        file = os.path.join(path,f)
        oldname = file
        newname = newpath + a + "." +b             #a为文件名,b为文件后缀
        shutil.copyfile(oldname,newname)
        #dom = xml.dom.minidom.parse('1533613434.xml')
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值