I have 39 shapefiles in a folder with each shp having 368 attributes. Every shapefile has the same attribute name (FID, pointid, grid code and 365/366 others; depending on them being leap year).

I am using the code below by @Aaron in their answer to Join field repeatedly on multiple tables.

I wanted to know whether the code below joins all the attributes from every shapefile to one shapefile or every attribute from other shapefiles to each shapefile i.e. If I have 50 shapefiles numbered 1 to 50 and I want to join fields from all the 49 shapefiles to shapefile 1, what changes (if any) would I have to make to the code. I only want one shapefile with attributes from every other shapefile.

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."
  • Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. What happens when you test the code that you have presented? – PolyGeo Nov 24 '19 at 3:21
  • Perhaps join 2 of them manually and see if you can make sense of resulting mess. – FelixIP Nov 24 '19 at 4:15
  • I ran the code for 4 hours. Till then only 14 of 39 shapefile had been processed. In the folder I could see that size of the files was changing. All 14 of them. So I cancelled it because it was taking a long time and I only wanted all the tables to be joined in only one shapefile. So I thought it was better to get a clarification on the code first so that I can run the code for 12-16 hours (or whatever it takes) – Rahul Nov 24 '19 at 4:16
  • Thanks @FelixIP, I will do that at once. Can't say why I didn't occured to me. – Rahul Nov 24 '19 at 4:17
  • I tried running the code with 5 shapefiles. I didn't get the intended result. While the 1st shapefile had entries from two shapefiles, the other aren't opening. It showed the error. "Error opening feature class. Number of shapes does not match the number of table records." – Rahul Nov 24 '19 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.