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)
And this is what the schema.ini file created by the script looks like"like:
[Sample_200.csv]
Format=CSVDelimited
ColNameHeader=True
REGISTRATION_NUMBER TEXT Width 128
Address TEXT Width 128
City TEXT Width 128
State TEXT Width 128
ZIP TEXT Width 128