Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Pretty simple question though I am struggling with how to operationalize this, I want to rename a shapefile based on the number of features it contains. My initial thoughts are that I would need to create a list of the shapefiles contained in a folder, for those shapefiles use arcpy.GetCount and where count >= X rename the shapefile. I used an if statement followed by arcpy.rename and it managed to rename all the shapefiles. Thanks for your help with this one.

share|improve this question
up vote 4 down vote accepted

Yep, this is a pretty straightforward script.

import arcpy, os

folder = ""
arcpy.env.workspace = folder

num = 50

for shp in arcpy.ListFeatureClasses():
   count = int(arpcy.GetCount_management(shp)[0])

   if count >= num
      base, ext = os.path.splitext(shp)
      #Append _ and the number of features in the shapefile to filename
      arcpy.Rename_management(shp, "{0}_{1}{2}".format(base, count, ext))

Edit: You might not have been able to get it work because GetCount_management() returns a result object that you can either get the value from with indexing (used here) or .getOutput(0). In order to be compared to another number, it needs to be cast to int, since the output is a string.

share|improve this answer
Thansk again @Paul, that was all I needed to do was cast as int. – standard Jul 22 '14 at 18:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.