I am trying to replace/rename feature Classes in a dataset like this

import arcpy
import os

arcpy.env.workspace = r"C:\\GDBs\Delaware.gdb\Kent"
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
    desc = arcpy.Describe(fc)
    gType = desc.shapeType
    if gType == "Polygon":
      outname = fc.replace('_','______')
      arcpy.Rename_management(fc, outname)

but I am getting this error

ERROR 000670: output Output Data Element is same as input Input Data Element Failed to execute (Rename).

Message File Name   Line    Position    
    <module>    <module1>   11      
    Rename  C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py 4515        
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000670: output Output Data Element is same as input Input Data Element
Failed to execute (Rename).

Can you please let me know what I am doing wrong?

closed as unclear what you're asking by PolyGeo Oct 27 '18 at 13:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Can you share one of the fc names? – smiller Oct 19 '18 at 17:08
  • 1
    Try adding another if: if outname != fc: and then rename line – BERA Oct 19 '18 at 17:11
  • 2
    If fc does not contain '_' then outname == fc – Vince Oct 19 '18 at 17:24
  • 1
    I agree with @smiller these sort of questions are difficult to answer if you do not supply examples of your input! Whilst it looks like you have found an answer it does help others seeking a solution to a similar problem. – Hornbydd Oct 21 '18 at 18:17

I don't know if this is in fact the issue you are having, but the first obvious thing to me would be to double check that there are in fact underscores in every feature class's name before trying to rename. If you try and rename 'ABC' with that code it will replace it with the same 'ABC' which seems to be what the error text you included is saying.

Maybe try adding to the code a test to check if there is a _ before renaming. For example, replace if gType == "Polygon": with if gType == "Polygon" and '_' in fc:

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