1

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")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 24, 2015 at 9:01

2 Answers 2

5

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.

answered Sep 24, 2015 at 9:22
2
  • yes, you are right, I was trying to use it with shapefiles rather than on feature classes. In this case, any thoughts? Commented 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). Commented Sep 24, 2015 at 9:31
1

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.

answered Sep 24, 2015 at 9:17
1
  • it was not formatted correctly. in the arcpy code block it was as you typed. Commented Sep 24, 2015 at 9:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.