I have to edit the Name of the feature classes in my databank by deleting the Suffix part called "_AAA_VV". I am not pro in ArcPy but prepared something which does not work.

Can you help to find my mistake?

import arcpy, os
database = r'C:...\Data_test.gdb' 

for dataset in datasets:
    arcpy.env.workspace = os.path.join(database,dataset)
    features = arcpy.ListFeatureClasses()
    for feature in features:
     #  feature.replace('_AAA_VV,'')

except Exception as e:
print("Found an error - {0}".format(e))

This should work

import arcpy

database = r'C:...\Data_test.gdb'
arcpy.env.workspace = database
datalist = arcpy.ListDatasets("*", "Feature")

for data in datalist:
        features = arcpy.ListFeatureClasses("*", "ALL", data)
        for feature in features:
            split = feature.split('_AAA_VV')
            arcpy.Rename_management(feature, split[0])
    except IndexError:
        print('Error found in feature - {0}'.format(feature))

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.