[Tutor] Can This Script Be Modified to Read Many Files?..

Sam Starfas starfas_s at yahoo.com
Mon Jan 25 16:34:58 EST 2016


Hi,I am very new to Python, but having fun learning. 
I need to have a script read all of the XML files contents that are in a directory, pull out the contents of an element, in my case <uicontrol>, and list them in an output file. I have this script that does exactly what I need. But in my beginning Python class we didn't go over reading all files, only one file at a time. 
Can the below script be modified to scan/read all of the XML files in a directory instead of just the file typed into the script? If so, how do I do this?
Thanks for all the help.Sam

import xml.etree.ElementTree as ETtree = ET.parse('TEST.xml')   <-- Want to read all the files in directory, not type in the filename.root = tree.getroot()

for uicontrol in root.iter('uicontrol'):    print(uicontrol.text)


More information about the Tutor mailing list