I am trying to change a field name in featureclasses (shapefiles) using AlterField_management, however I receive the following error message:
Runtime error Traceback (most recent call last): File "", line 14, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3332, in AlterField raise e ExecuteError: ERROR 000664: Invalid input: The type of dataset is not supported.
The code:
import arcpy
from os import path
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\johnny\trial'
for fc in arcpy.ListFeatureClasses():
fieldList = arcpy.ListFields(fc)
for field in fieldList:
#if field.baseName != "NEAR_DIST":
arcpy.AlterField_management(fc, 'NEAR_DIST', 'distance', "distance", "DOUBLE")
2 Answers 2
In the Help for arcpy.AlterField_management() it says with my bolding:
This tool provides the ability to rename fields or rename field aliases for any geodatabase table or feature class.
From your code the workspace that you have set, which is a folder, rather than a geodatabase, makes me think that you are trying to use this on shapefiles instead of feature classes.
-
yes, you are right, I was trying to use it with shapefiles rather than on feature classes. In this case, any thoughts?Tre– Tre2015年09月24日 09:30:02 +00:00Commented Sep 24, 2015 at 9:30
-
Renaming fields in shapefiles has been covered in earlier Q&A here. If you do not find that already answered then you should ask a new question (but research first).2015年09月24日 09:31:47 +00:00Commented Sep 24, 2015 at 9:31
Looks like you have an indentation problem - is the example formatted correctly?
The last few lines should be
for fc in arcpy.ListFeatureClasses():
fieldList = arcpy.ListFields(fc)
for field in fieldList:
#if field.baseName != "NEAR_DIST":
arcpy.AlterField_management(fc, 'NEAR_DIST', 'distance', "distance", "DOUBLE")
If fc has gone out of scope, it will be passed into AlterField_management as None and would generate an invalid input error.
-
it was not formatted correctly. in the arcpy code block it was as you typed.Tre– Tre2015年09月24日 09:28:54 +00:00Commented Sep 24, 2015 at 9:28