3

I have a directory of hundreds of *.csv files, containing code/description pairs for geodatabase domains. I'm trying to automate the creation of these domains using Python.

  1. If I manually run the Table to Domain tool using a *.csv file in ArcToolbox, the domain is correctly created
  2. If I create a Model using the Table to Domain tool, hard-coding in the input file (and all other parameters) then export this to a Python script, the domain is correctly created when I run the Python script
  3. If I try to iterate through all *.csv files in the directory, running the Table to Domain tool for each file, I get the ""Dataset xxx does not exist or is not supported" error message:

Failed to execute. Parameters are not valid.ERROR 000732: Input Table: Dataset C:\temp\01-01.csv does not exist or is not supported ERROR 000308: Invalid field type Failed to execute (TableToDomain).

I suspect the problem is due to the path not being correct for the *.csv file, but I can't work out how to get it working. os.path.exists shows that the file does exist, so it may be an internal ArcGIS thing.

Note that the *.csv file does work correctly via ArcToolbox and the hard-coded Python script, so it's unlikely that the field type really is invalid.

3 Answers 3

1

Is schema.ini file available in the folder?

If YES then most probably it column data type problem.

See this thread for setting column type in schema.ini for ArcGIS

1
  • this wasn't the issue, but for the record it only listed Format=CSVDelimited for each file, not the column types Jul 24, 2012 at 22:41
1

It looks like the slashes in the script exported from your model are "escaped" but not in the code you wrote is mode code "C:\temp\01-01.csv" your code "C:/temp". maybe you could try using raw strings instead. Also your model uses a backslash and you use a forwardslash.

have you tryed using something like arcpy.ListFiles("*.csv") to find the csv files you are interested in?? maybe that would be easier. Hope that helps

1

The problem was that the file was still open in Python while I was trying to use it in ArcGIS. The answer is to close the file in Python once it's been read in:

 f = open(file, 'r')
 header = f.readline().split(",")
 f.close()

There is arguably poor wording on the error message - it's not that the file doesn't exist, but that it was locked.

1
  • 2
    you can use this arcpy.TestSchemaLock() to test if the file is locked, but this might only work if the file is locked by arcpy. Thanks for posting the answer!.
    – dango
    Jul 24, 2012 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.