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_','')
How do I make it rename all the shapefile components?
You'd want to use python (not arcpy) to rename all the files. But... Since your moving the shape file why not just rename it as you move it to your egdb? See Copy Features—Data Management toolbox | ArcGIS Desktop
If the naming convention is consistent, i.e., you always want everything after an underscore, does this work for you?
>>> name = r"dbo.vNT_Fence.shp"
>>> arcpy.Rename_management(name, name.split("_"))
I've had a chance to try making this script work again. Thank you all for your help.
I think I'm going to go with the copy features option.
The code above only renames the .shp file and not the others. In theory do I need to use a wildcard instead of .shp?