how to rename the correct shapefile

Discussion created by helenak on Sep 22, 2012
Latest reply on Sep 23, 2012 by m.gasior
System ArcGIS 9.3
Windows Vista


I have some shapefiles at hand. (georCXXXX)
Each has a field called CXXXX.
In this field, one of the value is "S." (string)
I want to extract the "S" part of the shapefiles.
Then, I want to make the S part another shapefile and call it as CXXXXS.

The code was created but an error happened in naming the S part shapefile.
Instead of the S part shapefile (Outfeatureclass),
it was the original shapefiles renamed as georCXXXXS.
Please kindly advise modification to give the S part shapefile the name CXXXXS.
Thank you

##Script Name: split rows 
##Created By: Elaine Kuo
##Date: 24/09/2012

#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the workspace.
gp.Workspace= "H:/temp/test1"

#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp/test1"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Loop through every item in the list that was just generated
for fc in fcs:

    # Break out the name, no path or extension, using the describe object.
    desc = gp.describe(fc)
    featureName = desc.name
    # Make featureclasses as layers
    gp.OverWriteOutput = 1
    gp.toolbox = "Data Management"

    #   Get a list of the fields in the featureclass
    fields = gp.ListFields(fc, "C*", "String")
    # Loop through every item in the list that was just generated 
    for field in fields:

        gp.toolbox = "Data Management"

        # Select records to be deleted (C*, i.e. C7658)
        # Make temporary featureclasses
        gp.toolbox = "Data Management"
        query = "\"%s\" = 'S'" % field.Name
        gp.SelectLayerByAttribute("lyr", "NEW_SELECTION", query)

        #Validate the new feature class name for the output workspace.
        OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)    

        # copy feature
        gp.CopyFeatures("lyr", OutFeatureClass)
    #get file name
    fcName, fcExt = os.path.splitext(fc) 

    # replace the strings you want to
    fcName = fcName.replace("_Dissolve"," ")
    fcName = fcName + fcExt

    # rename the files
    gp.Rename_management(fc, fcName)   

print gp.GetMessages()