I need to create a python script (or model) that would first rename all the feature datasets in a gdb. The feature dataset is in a set format and I need to change the prefix of the dataset.
For example: from "H2611111:xxx" to "gen26_xxx"
– where xxx is the string that I need to keep and prefix of "H2611111" is a constant that I need to replace with "gen26_".
Once this is completed, I would then need to rename each feature class inside each renamed dataset. The feature classes needs to be prefixed with the newly renamed dataset separated by an underscore.
For example:
in dataset gen26_xxx:
from "test1" to "gen26_xxx_test1"
from "test2" to "gen26_xxx_test2"
in dataset gen26_zzz:
from "new1" to "gen26_zzz_new1"
I am using ArcGIS Desktop 10 and 9.3.1.
Best Answer
A good solution is a combination of ListDatasets() and Rename().
The basic solution is:
arcpy.ListDatasets()
to get a list of all datasets.arcpy.Rename_management(oldName, newName)
'gen26_' + oldName.split(':')[1]
To do the same now for each feature class within the datasets.
arcpy.ListDatasets()
to get a list of all the datasets (since you just renamed them)arcpy.ListFeatureClasses()
to get a list of the feature classesarcpy.Rename_management()
like above with the new nameNote you can easily combine the above steps if you list datasets, list the feature classes in the workspace, rename all the feature classes, and now you can rename the dataset as well. For more on string manipulation, read here