3

I have built this code to specifically identify a load of .XML files and to extract co-ordinates from those files. Here is my code:

from xml.etree import ElementTree as ET
import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

workspace = "D:/J040083"
gp.workspace = workspace

for root, dirs, filenames in os.walk(workspace): # returms root, dirs, and files
    for filename in filenames:
        filename_split = os.path.splitext(filename) # filename and extensionname (extension in [1])
        filename_zero = filename_split[0]
        extension = str.upper(filename_split[1])

        try:
            first_2_letters = str.upper(filename_zero[0] + filename_zero[1])
        except:
            first_2_letters = "XX"

        if first_2_letters == "LI" and extension == ".XML":
            tree = ET.parse(workspace)
            print tree.find('//{http://www.opengis.net/gml}lowerCorner').text
            print tree.find('//{http://www.opengis.net/gml}upperCorner').text

I am having trouble with an error:

Message File Name   Line    Position    
Traceback               
    <module>    D:\J040083\TXT_EXTRACTION.py    32      
    parse   C:\Python25\Lib\xml\etree\ElementTree.py    862     
    parse   C:\Python25\Lib\xml\etree\ElementTree.py    579     
IOError: [Errno 13] Permission denied: 'D:/J040083'     

I definitely do have access to this folder! I have also tried making new, empty folders and putting just one .xml file in there but i get the same error! Does anyone have any idea what has gone wrong?

SilentGhost
  • 307,395
  • 66
  • 306
  • 293
Alice Duff
  • 667
  • 6
  • 11
  • 18
  • Can you tell us what line 32 contains in the TXT_EXTRACTION.PY script? The text box in the question doesn't have that many lines. – mguillech Jan 19 '11 at 15:28

2 Answers2

11

You need to change the line

tree = ET.parse(workspace)

to

tree = ET.parse(filename)

because workspace is a directory and the parse method takes a filename.

Spaceghost
  • 6,835
  • 3
  • 28
  • 42
0

Maybe you just need to write the file path with \ instead of /:

workspace = "D:\\J040083"

Or, without backslash escaping as a raw string:

workspace = r"D:\J040083"
sth
  • 222,467
  • 53
  • 283
  • 367