I'm trying to clean up a list of shapefiles that I've created using GME. I have a series of shapefiles (polylines and polygons) that are named "ID_final_kde.img_LSCV.shp" and "ID_final_kde.img_LSCV_poly.shp", where ID is unique to each individual. I'm trying to rename the polylines to "ID_final_LSCV.shp" and the polygons to "ID_final_LSCV_poly.shp", to no avail.
Here's what I've been trying:
# import modules
import arcpy, os, arcinfo, xlwt,time, glob
from arcpy.sa import *
arcpy.CheckOutExtension('spatial')
path = os.getcwd()
arcpy.env.workspace = path + '\\fawn_locations\\FINAL'
arcpy.env.overwriteOutput = True
lines=arcpy.ListFeatureClasses(feature_type='Polyline')
for each in lines:
arcpy.Rename_management(each, each[:-16] + 'LSCV')
poly=arcpy.ListFeatureClasses(feature_type='Polygon')
for each in poly:
arcpy.Rename_management(each, each[:-20] + 'LSCV_poly')
This code renames the .shp file, but not the associated .cfg, .prj, or .shx files, so I can no longer open the shapefile in ArcMap. How can I loop through the folder, renaming all the files while preserving their extensions?
I'm just learning python.
each.replace("kde.img_")
. That way, you don't need to loop over lines and polygons separately.for each in folder: each.replace("kde.img_")
andeach.replace("kde.img_", "")
but neither seemed to rename anything.