Renaming a shapefile in Python 2.7

1757
10
09-09-2019 07:20 PM
BlytheSchembri1
New Contributor III

Hi guys

I have a python script (written in 2.7) with takes a shapefile, renames it and then imports it into a SDE geodatabase. The creators of the shapefile have recently changed the file name to have a full stop halfway through the name which now causes the script to crash. 

I have tried running the following section of python to rename the shapefile but it only renames the .shp file and no other files that are part of the shapefile:

arcpy.env.workspace = "C:\\Users\\blythe schembri\\Downloads"
datasets = arcpy.ListFeatureClasses()
for fc in datasets:
      CorrectName = fc.replace('dbo.vNT_','')
arcpy.Rename_management(fc, CorrectName[:-4])

How do I make it rename all the shapefile components?

Thanks

Blythe

0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus

Copy Features—Data Management toolbox | ArcGIS Desktop 

would be your best option to recreate the old shapefile under a new name and to make a featureclass.

Your original would be retained, and could be archived if needed or dumped via windows explorer 

0 Kudos