I need to open multiple XML files for some calculations; my problem is, sometimes these files would open, but the next time they wouldn't, so I cannot trust my code whether it's working right or not:
The piece of code for opening multiple files is:
path_EJ11 = r'C:\Users\Owner\Python\EJ11'
Data_EJ11 = []
for filename in os.listdir(path_EJ11):
dataa_EJ11 = []
#cols_EJ11 = []
with open(filename, 'r') as content:
tree = ET.parse(content)
root = tree.getroot()
for i, child in enumerate(root):
dataa_EJ11.append([subchild.text for subchild in child])
#cols_EJ11.append(child.tag)
Data_EJ11.append(dataa_EJ11)
but the error I'm getting is:
FileNotFoundError: [Errno 2] No such file or directory: 'corr_1060.xml'
It seems to me the code cannot open the file, Although this file exists in the directory EJ11. Any comment is appreciated; thanks.