Skip to main content
added 151 characters in body
Source Link
MacroZED
  • 2.3k
  • 1
  • 15
  • 22

You're trying to split an arcpy object using the os module. You are only renaming the .shp extention of the component file. You are not renaming the shapefile, and all its components.

There's an easier way to rename feature classes or shapefiles using the arcpy.Describe function. See more information here.

Try this:

import os import arcpy from arcpy import env folder = r'\TESTRENAME' arcpy.env.workspace = folder lfc = arcpy.ListFeatureClasses() for fc in lfc: desc = arcpy.Describe(fc) newname = desc.baseName.replace(".", "_") arcpy.Rename_management(fc, newname) 

Or another way is to just use the replace function directly, so:

for fc in lfc: arcpy.Rename_management(fc, fc.replace(".", "_")) 

You're trying to split an arcpy object using the os module. You are only renaming the .shp extention of the component file. You are not renaming the shapefile, and all its components.

There's an easier way to rename feature classes or shapefiles using the arcpy.Describe function. See more information here.

Try this:

import os import arcpy from arcpy import env folder = r'\TESTRENAME' arcpy.env.workspace = folder lfc = arcpy.ListFeatureClasses() for fc in lfc: desc = arcpy.Describe(fc) newname = desc.baseName.replace(".", "_") arcpy.Rename_management(fc, newname) 

You're trying to split an arcpy object using the os module. You are only renaming the .shp extention of the component file. You are not renaming the shapefile, and all its components.

There's an easier way to rename feature classes or shapefiles using the arcpy.Describe function. See more information here.

Try this:

import os import arcpy from arcpy import env folder = r'\TESTRENAME' arcpy.env.workspace = folder lfc = arcpy.ListFeatureClasses() for fc in lfc: desc = arcpy.Describe(fc) newname = desc.baseName.replace(".", "_") arcpy.Rename_management(fc, newname) 

Or another way is to just use the replace function directly, so:

for fc in lfc: arcpy.Rename_management(fc, fc.replace(".", "_")) 
Source Link
MacroZED
  • 2.3k
  • 1
  • 15
  • 22

You're trying to split an arcpy object using the os module. You are only renaming the .shp extention of the component file. You are not renaming the shapefile, and all its components.

There's an easier way to rename feature classes or shapefiles using the arcpy.Describe function. See more information here.

Try this:

import os import arcpy from arcpy import env folder = r'\TESTRENAME' arcpy.env.workspace = folder lfc = arcpy.ListFeatureClasses() for fc in lfc: desc = arcpy.Describe(fc) newname = desc.baseName.replace(".", "_") arcpy.Rename_management(fc, newname)