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

I have over 60 shapefiles, all in their own folders. I'm looking to add a field titled "Name" and then populate it with the name of the shapefile. I want to be able to do this so that I can then merge the files together while retaining a unique identifier for each. I can do this by hand of course, but would like to script it. I don't know Python and I'm familiar though not very experienced with ModelBuilder. I'm using ArcGIS 10. Thanks!

share|improve this question

3 Answers 3

This will do it

import arcpy
arcpy.env.workspace = r'c:\temp\x'
fcs = arcpy.ListFeatureClasses()

for fc in fcs:
  arcpy.AddField_management(fc, 'shpname','text')
  arcpy.CalculateField_management(fc, 'shpname', '"'+fc+'"')
arcpy.Merge_management(fcs, 'out.shp')
share|improve this answer
Thanks, that's perfect! – tncgis Mar 11 '11 at 17:39
@tncgis, if this answers your question, please use the checkmark to mark it so. Thanks! – matt wilkie Mar 11 '11 at 18:40
Sorry to dig out and old post, but can someone explain where the layer name comes from in the calculate field formula? I don't understand the '"'+fc+'"' bit. Thanks – TreeMan Mar 11 at 14:34

For python the pieces needed are: os.path.walk to recurse through the directories, arcpy.ListFeatureClasses in each to generate lists of shapes to operate on, from there you can use the add field tool to add and populate a 'Name' field.

I'll let someone else address a modeller or toolbox approach, with one parting shot: most people don't realise all the tools have a batch mode. Right click on the tool, select batch, then drag'n'drop inputs from Arccatalog. Sometimes a lot faster for the human than building a model or script.

share|improve this answer
Thanks Matt, that was a helpful start. – tncgis Mar 11 '11 at 17:40

GeoWizards is faster than the ArcGIS Append tool (preserves file name locations)

If purchased you will have access to the tools and the scripts to execute the function you want. (the free version does not allow this scripting function)

share|improve this answer

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.