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')