0
This is my code
from xml.dom import minidom
import os, shutil
os.chdir("E:\\")
xmldoc = minidom.parse('123.xml')
itemlist = xmldoc.getElementsByTagName('File') #TagName
print len(itemlist)
print itemlist[0].attributes['name'].value
for s in itemlist :
shutil.move(s.attributes['name'].value, "E:\\Junk\\") #Moving to another location
上面的代码找到标记并获取它的值。Python:如何从xml文件的标记名称中删除文件扩展名
我的XML文件是这样
<File>
<File name="E:\qwer\abc.exe"/>
<File name="E:\qwer\xyz.dll"/>
<File name="E:\pqr\bc.exe"/>
</File>
如何删除 “abc.exe”?有没有什么方法可以在xml中搜索扩展名,然后将其删除? 最终的XML应该是这样的
<File>
<File name="E:\qwer\"/>
<File name="E:\qwer\"/>
<File name="E:\pqr\"/>
</File>
很抱歉,如果我的问题听起来含糊
这是OP更新他的问题后澄清的正确答案。 –
非常感谢。它起作用 – heycooldude
如果脚本在UNIX计算机上运行,但路径名是Windows路径,这可能会搞砸。 –