Skip to main content
7 of 9
added 21 characters in body

Schema.ini file not being honored by ArcMap, string fields still being converted to numbers when importing CSV to GDB

I am trying to import a CSV to GDB using an ArcMap script tool and preserve some string fields that look like numbers as strings. I added some code to create and populate a schema.ini file in the CSV's source directory but ArcMap doesn't seem to recognize/honor it. It is created immediately but appears to only be populated a minute or so later once the rest of the tool is finished running. The new schema.ini file appears to be identical to one I manually edited that does work. It seems to possibly be an order of operations issue, any suggestions? Here is my code for this piece of the workflow so far:

addressTable = arcpy.GetParameterAsText(0)
tableName = os.path.basename(addressTable)
inputDir = os.path.dirname(addressTable)
schemaFile = str(inputDir) + "\schema.ini"
schemaHeader = "[" + str(tableName) + "]\n"

file = open(schemaFile, 'w')
file.write(schemaHeader)
file.write("Format=CSVDelimited\n")
file.write("ColNameHeader=True\n")
fieldList = arcpy.ListFields(addressTable)
for field in fieldList:
    file.write(field.name + " TEXT Width 128\n")
file.close               
arcpy.conversion.TableToTable(addressTable, workingGDB, tempTable)