Remove Special Characters from Geo database Feature Classes

329
2
Jump to solution
02-02-2023 09:59 AM
TomDonovan-Brady1
New Contributor II

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 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

 

gdbname = r'<GDB_Name>.DBO.B_H_Limited_Waiting_M_S_8AM_6PM'

newgdbname = gdbname.replace('_', '')

print(newgdbname)

 

View solution in original post

2 Replies
by Anonymous User
Not applicable

 

gdbname = r'<GDB_Name>.DBO.B_H_Limited_Waiting_M_S_8AM_6PM'

newgdbname = gdbname.replace('_', '')

print(newgdbname)

 

DannyMcVey
Esri Contributor
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('_', '',))
0 Kudos