[GIS] Join field repeatedly on multiple tables

arcgis-10.1arcgis-desktopattribute-joinsattribute-tableshapefile

I have a fifty or so shapefiles. All of them have similar attribute tables with identical field titles. I also have a standalone table with data that I want to add to every single attribute table based on a shared field (DATE).

This is easy individually using the "Join Field" tool, but on my computer it takes a long time (almost seven minutes per file), and I have to stay near the computer to start the next file.

Is it possible to set it up to run on every single shapefile in the batch? I want to let it run while I'm away from the computer.

Best Answer

Folks usually automate tasks such as yours with Python and the ArcGIS arcpy site package. Here is a script to get you started. This essentially loops over a folder of shapefiles and joins a common table to each. I would recommend creating a copy of your original shapefiles when running this script as the JoinField_management tool alters the original data.

import arcpy

arcpy.env.workspace = r'C:\path\to\your\shapefiles_folder'

join_field = "DATE"
join_table = r'C:\path\to\your\jointable.dbf'
shps = arcpy.ListFeatureClasses()

counter = 1
for shp in shps:
    arcpy.JoinField_management(shp, join_field, join_table, join_field)
    print "%s of %s shapefiles processed" % (counter, len(shps))
    counter += 1

print "Processing complete."
Related Question