I have a script that renames and copies files (feature classes) on an SDE connection. This script works just fine if the feature class name does not start with an 'S'. If the feature class name does start with an 'S', it gets removed. As you can see in the script below I use Python's
lstrip to remove the 'SDE.' from the file name to rename it. The 'SDE.' gets added again automatically after copying. So a feature class named
HAM would be renamed
SDE.R_HAM_QC. If the feature class is named
STREETS it get renamed to
SDE.R_TREETS_QC. See how the first
STREETS is removed? Does anyone have a possible solution?
#Import modules import arcpy, os, sys from arcpy import env arcpy.env.overwriteOutput = True #Set variables outWorkspace = "Database Connections\Connection to 10.2.5.468.sde" arcpy.env.workspace = outWorkspace fileName = "SDE.STREETS" #Describe the file name desc = arcpy.Describe(fileName) if desc.datasetType == "FeatureClass": #Rename and copy data if it is a feature class name1 = fileName.lstrip('SDE.') print name1 newName = "R_" + name1 + "_QC" outFile = os.path.join(outWorkspace, newName) arcpy.Copy_management(fileName, outFile)