Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 S in STREETS is removed? Does anyone have a possible solution? Thank you.

    #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)
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

What about slicing off the 'SDE.' part instead?

>>> fc = 'SDE.whatever'
>>> fc[4:]
'whatever'
share|improve this answer
    
That was it! My files are getting renamed properly now. Thank you for the quick response, Chad. –  Patty Jula Dec 21 '11 at 16:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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