Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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've placed a package here containing the template geodatabase, the working and broken python scripts, a few of the CSVs and the model which was used to export the working python script.

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.

Any help gratefully received.

Steve

share|improve this question
add comment

3 Answers 3

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

share|improve this answer
    
this wasn't the issue, but for the record it only listed Format=CSVDelimited for each file, not the column types –  Stephen Lead Jul 24 '12 at 22:41
add comment

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

share|improve this answer
add comment
up vote 1 down vote accepted

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.

share|improve this answer
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 '12 at 8:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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