AnsweredAssumed Answered

copyfield based on Cxxxx

Question asked by helenak on Jun 25, 2013
Latest reply on Jun 27, 2013 by rdharles
System: Windows Vista and ArcGIS 9.3

Hello,

I have 100 shapefiles called geocXXXX.shp (geoc0782, geoc9838, and geoc6728 etc)

In each shapefile, there is a field call CXXXX (C0782, C9838, and C6728 etc).
The field property is string, length =6.

Now I would like to make a new field call CXXXXD (C0782D, C9838D, and C6728D etc).
The field property is long integer, length =9.

Please kindly advise how to modify the follow code and thank you.

##Script Name: Copy field ##Description: Copy field using CXXXX ##Created By: Elaine Kuo ##Date: 06/25/2013   #Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)  #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "H:/temp_D/test"  #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D"  #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      #Validate the new feature class name for the output workspace.     OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)      #get file name     fcName, fcExt = os.path.splitext(fc)          #   Get a list of the fields in the featureclass     fields = gp.listFields(fc, "C*", "String")      # replace the strings you want to     fcName = fcName.replace("D","")     fcName = fcName + fcExt     fcName = outWorkspace + os.sep + fcName          #get file name     fcName, fcExt = os.path.splitext(fc)      fieldName = fcName + "D"  #build field name      #Add field to each SHP     gp.AddField_management(fc, fieldName, "LONG", 9, 3)

Outcomes