# coding:utf-8
import os
import os.path
import xml.dom.minidom
import shutil
path = r'D:\03_data\Annotations'
path_after = r'D:\03_date\03_data\ann_1'
# path="../xml/"
files = os.listdir(path) # 得到文件夹下所有文件名称
s = []
for xmlFile in files: # 遍历文件夹
if not os.path.isdir(xmlFile): # 判断是否是文件夹,不是文件夹才打开
# print(xmlFile)
# xml读取操作
# 将获取到的xml文件名送入到dom解析
# 错误代码:dom=xml.dom.minidom.parse(xmlFile)
dom = xml.dom.minidom.parse(os.path.join(path, xmlFile))
root = dom.documentElement
###获取标签对width的值
width = root.getElementsByTagName('width')
height = root.getElementsByTagName('height')
wid = width[0]
hei = height[0]
if float(wid.firstChild.data) == float(0) or float(hei.firstChild.data) == float(0) :
print(xmlFile)
print(wid.firstChild.data)
path_new = path+"\\"+xmlFile
print(path_new)
shutil.move(path_new, path_after)
# shutil.move(xmlFile, path_after)
004_查找xml中size为0的
最新推荐文章于 2022-12-05 10:58:03 发布