AnsweredAssumed Answered

rename_management failed

Question asked by helenak on Jan 3, 2013
Latest reply on Jan 4, 2013 by Wayne_Whitley
System ArcGIS 9.3
python 2.5

Hello,

I have 100 polygon shapefiles in a folder (file names: geoc0923, geoc7634, and geoc3923).
Each of them has a field called CXXXX (string).
For example, geoc0923 has the field C0923.

I tried to dissolve the 100 polygon shapefiels based on the CXXXX field ("R").
The dissolve process went smoothly, but some error appeared when renaming the output shapefile.

The error shows
gp.rename_management("outputR.shp", fcName)
ExecuteError: ERROR 000012: H:/temp/test\geoc0387.shp already exists
Failed to execute (Rename).

Please kindly advise correction on the code below.
thank you

#Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)   #Set the workspace. gp.Workspace= "H:/temp/test"  #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp"  #----------------------------------------------------------------- #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          #   Get a list of the fields in the featureclass     fields = gp.listFields(fc, "C*", "String")  #Select R  #-----------------------------------------------------------------              # Loop through every item in the list that was just generated      for field in fields:          gp.toolbox = "Data Management"         gp.addMessage(type(field))          # Select records (C*, i.e. C7658)         # Make temporary featureclasses         gp.toolbox = "Data Management"         query = "\"%s\" = 'R'" % field.Name              gp.select_analysis(fc,("outputR.shp"),query)          gp.Dissolve_management(fc,("outputR.shp"), field.Name)          #get file name         fcName, fcExt = os.path.splitext(fc)           # replace the strings you want to         fcName = fcName.replace("_Dissolve","")         fcName = fcName + fcExt          gp.rename_management("outputR.shp", fcName)         gp.delete("outputR.shp")      gp.AddMessage(gp.GetMessages()) print gp.GetMessages()

Outcomes