Hello, I am using ArcPRO 2.9, and I would like to run this script within the python window in ArcPRO. I have a lot of Geodatabase Feature Classes that have a '_' in various places in the file name. Is there a way with Python to remove '_'? Unfortunately, they are not in the same place; most online help I have found refers to a specific character being replaced.
So currently, I have
<GDB_Name>.DBO.B_H_Limited_Waiting_M_S_8AM_6PM.
I want it to look like this
<GDB>.DBO.BHLimitedWaiitngMS8am6pm.
I do not need to keep any '_', so they can all be removed.
Any help, I would be most grateful.
Tom
Solved! Go to Solution.
gdbname = r'<GDB_Name>.DBO.B_H_Limited_Waiting_M_S_8AM_6PM'
newgdbname = gdbname.replace('_', '')
print(newgdbname)
gdbname = r'<GDB_Name>.DBO.B_H_Limited_Waiting_M_S_8AM_6PM'
newgdbname = gdbname.replace('_', '')
print(newgdbname)
import arcpy
arcpy.env.workspace = "c:/data/gdb.gdb"
for fc in arcpy.ListFeatureClasses():
if "_" in arcpy.Describe(fc).name:
arcpy.management.Rename(fc, arcpy.Describe(fc).name.replace('_', '',))