Skip to main content
5 of 5
Made title better match question
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Looping through list of shapefiles to rename them using ArcPy?

I am trying to upgrade a simple script to list all shapefiles in a folder and if necessary in any folders within and then loop through the list of shapefiles and rename them.

import arcpy

# Set work environment
arcpy.env.workspace = "C:\\Users\\Rachael\\Documents\\Export"

# List shapefiles in folders
shp = arcpy.ListDatasets()

try:
  for shp in arcpy.ListDatasets():
    if arcpy.Exists("Histori2.shp"):
      arcpy.Rename_management("Histori2.shp", "H_BEV_CANS.shp")
Rachael
  • 33
  • 1
  • 1
  • 3