<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: rename_management failed in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138018#M10795</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed the code already.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please follow the second last response.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Jan 2013 23:34:03 GMT</pubDate>
    <dc:creator>ElaineKuo</dc:creator>
    <dc:date>2013-01-03T23:34:03Z</dc:date>
    <item>
      <title>rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138013#M10790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;System ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;python 2.5&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have 100 polygon shapefiles in a folder (file names: geoc0923, geoc7634, and geoc3923).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Each of them has a field called CXXXX (string). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, geoc0923 has the field C0923. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to dissolve the 100 polygon shapefiels based on the CXXXX field ("R").&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The dissolve process went smoothly, but some error appeared when renaming the output shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error shows &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.rename_management("outputR.shp", fcName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 000012: H:/temp/test\geoc0387.shp already exists&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Rename).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly advise correction on the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Import standard library modules import arcgisscripting import os&amp;nbsp; #Create the Geoprocessor object gp = arcgisscripting.create(9.3)&amp;nbsp;&amp;nbsp; #Set the workspace. gp.Workspace= "H:/temp/test"&amp;nbsp; #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp"&amp;nbsp; #----------------------------------------------------------------- #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses()&amp;nbsp; # Loop through every item in the list that was just generated for fc in fcs:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object. &amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc) &amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass &amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")&amp;nbsp; #Select R&amp;nbsp; #-----------------------------------------------------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.toolbox = "Data Management" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addMessage(type(field))&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select records (C*, i.e. C7658) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.toolbox = "Data Management" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "\"%s\" = 'R'" % field.Name &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.select_analysis(fc,("outputR.shp"),query)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management(fc,("outputR.shp"), field.Name)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc)&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # replace the strings you want to &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName.replace("_Dissolve","") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName + fcExt&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.rename_management("outputR.shp", fcName) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.delete("outputR.shp")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(gp.GetMessages()) print gp.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:04:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138013#M10790</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2013-01-03T21:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138014#M10791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Elaine, I see you are starting the new year trying to wrap up a task from yesteryear --- well, hope you are close to the finish so you can open up the year with new and exciting challenges, what do you say, are you ready?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to start with the obvious- 1st of all, you do not have the overwriteoutput property set, so that's 1 reason your code throws the error.&amp;nbsp; Moreover, you have a nested loop - looping on fields and in turn looping on fcs...it doesn't really make sense to create an output based on input, then within the loop attempt overwriting the same fc you are using for input, do you see?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am going to guess based on your variables toward the beginning that you'd like to fetch all fcs from an input directory (which i assume is working fine) and use an output directory as you have attempted to define with outWorkspace?&amp;nbsp; You have to 'assemble' the appropriate pathname, then you won't have the renaming error - everything will be going to the root you defined...there are several 'less than optimal' practices going on in your code, but let's start with isolating the direct cause of your error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have I made the correct assumption that outWorkspace is your intended output folder?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 22:44:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138014#M10791</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-03T22:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138015#M10792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So try this, provided you want output to go to that defined by your outWorkspace variable---&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enter the following line just before your line gp.rename...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fcName = outWorkspace + os.sep + fcName&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 22:53:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138015#M10792</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-03T22:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138016#M10793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I followed the advice and corrected the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, the resulting shapefile is named as geoc0923_shp.shp.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, I want it to be called as geoc0923_dissolve.shp&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly advise how to revise the section of " replace the strings you want to" in the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW, encouraging greetings are thanked but could be shortened next time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Happy New Year&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#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:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace.
&amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc) 

&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # replace the strings you want to
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName.replace("_Dissolve","")
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = fcName + fcExt
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = outWorkspace + os.sep + fcName
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management(fc,OutFeatureClass, field.Name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138016#M10793</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2021-12-11T07:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138017#M10794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually, I don't think 'rename' will work that way take out the gp.rename line and replace it with copy features below (keep the previously inserted line from last post).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CopyFeatures_management("outputR.shp", fcName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the copy features webhelp:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Copy%20Features%20(Data%20Management)"&gt;http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Copy%20Features%20(Data%20Management)&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 23:23:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138017#M10794</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-03T23:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138018#M10795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed the code already.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Please follow the second last response.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 23:34:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138018#M10795</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2013-01-03T23:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: rename_management failed</title>
      <link>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138019#M10796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Elaine, I'll be as brief as I can:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I see what you are trying to do...nice try with writing the Dissolve output directly to your outWorkspace but your new string variable, OutFeatureClass, is formed incorrectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ValidateTableName is 'looking' at the whole fc name provided, geoc0923.shp, so auto-replaces invalid characters like '.' with '_' and evaluates the output location to apply the necessary shapefile ext - not 'smart enough' to realize it's the same file extension and just does the grunt work...&amp;nbsp; The funny thing about your code is that you've included 3 different ways to attempt getting at the file name (minus ext) - using decribe, validate, and splitext.&amp;nbsp; Also, incorrect usage of 'replace'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since we're just dealing with shapefiles, why not simply do it this way?? (just working with what you already have in your loop):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Loop through every item in the list that was just generated
for fc in fcs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #get file name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName, fcExt = os.path.splitext(fc) 

&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.listFields(fc, "C*", "String")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Is 'fields' supposed to contain a single field?&amp;nbsp; If so, then you need this line:
&amp;nbsp;&amp;nbsp;&amp;nbsp; field = fields[0]

&amp;nbsp;&amp;nbsp;&amp;nbsp; # replace the strings you want to
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcName = os.path.join(outWorkspace, fcName + "_Dissolve") + fcExt
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management(fc, fcName, field.Name)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:39:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/rename-management-failed/m-p/138019#M10796</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T07:39:26Z</dc:date>
    </item>
  </channel>
</rss>

