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")

2 Answers 2

4

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.

2
  • yes, you are right, I was trying to use it with shapefiles rather than on feature classes. In this case, any thoughts?
    – Tre
    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).
    – PolyGeo
    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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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