“ERROR 000840: The value is not a Data Element” while scripting Rename_management

I am trying to use a script to go through a folder full of geodatabases, open each geodatabase, and rename the feature classes inside the same name as the geodatabase it resides in.

For example, for a folder like this....

MyFolder
Geodatabase1.gdb
Points, Polylines
Geodatabase2.gdb
Polylines
Geodatabase3.gdb
Points


I want...

MyFolder
Geodatabase1.gdb
Geodatabase1_Points, Geodatabase1_Polylines
Geodatabase2.gdb
Geodatabase2_Polylines
Geodatabase3.gdb
Geodatabase3_Points


My code to do this is giving me the error arcgisscripting.ExecuteError:Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Data Element. Failed to execute (Rename). Can anyone see what might be the issue?

Here is my code:

outLocation = r"C:\Path\to\MyFolder"
arcpy.env.workspace = outLocation
MasterGDB = outlocation + 'excludedGDB.gdb'

for fgdb in arcpy.ListFiles():

if fgdb.endswith('.gdb') and fgdb != MasterGDB:

arcpy.env.workspace = os.path.join(outLocation, fgdb)
featureDataset = arcpy.ListDatasets()[0]
featureClasses = arcpy.ListFeatureClasses(feature_dataset= featureDataset)

for fc in featureClasses:
in_data = fc
out_data = fgdb +'_'  + fc
data_type= "FeatureClass"
arcpy.Rename_management(in_data, out_data, data_type)

else:
print fgdb + " is not a gdb or has been otherwise excluded."

• With fgdb != MasterGDB you are comparing a geodatabase name (for example test123.gdb) with a full path and name to a geodatabase (C:\test\test3456.gdb). This will always be false. You should also take a look at os.path.join for combining paths and file names – BERA Jan 16 '17 at 9:01