2

How to remove the "w" from these file geodatabase classes using ArcPy?

Tried this code snippet but does not work:

enter image description here

import arcpy
from arcpy import env
env.workspace = "C:\shared\NCWD\Testing\Castic_FGDB.gdb"
in_data = "wValve"
out_data = "Valve"
arcpy.Delete_management(out_data)
  • 1
    What happened when you tried this? The error messages provided by Python are always informative. – PolyGeo May 22 '17 at 20:25
3

since your in_data variable is a string you should be able to use in_data[1:] to get the string without the first character.

Edit: Sorry, I think I misread your question. I think you want to know how to remove the first character for all files in the file geodatabase. To do so you want to list all inside the database and loop through it and perform the Rename function.

For reference:

http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/rename.htm

http://desktop.arcgis.com/en/arcmap/10.3/analyze/python/listing-data.htm

4

Discovered the correct script!

import os

import arcpy
arcpy.

env.workspace = "C:/shared/NCWD/Testing/Castic_FGDB.gdb"

fcs = arcpy.ListFeatureClasses("c*","All","cWaterDistributionNetwork")

for fc in fcs:

      print(fc)
      arcpy.Rename_management(fc,fc[1:])
print "all done"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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