Select to view content in your preferred language

Copy attribute table fields from one shapefile to another

18885
13
Jump to solution
09-09-2015 01:04 PM
KeithAddison1
Frequent Contributor

I have about 20 shapefiles that all need to have the same attribute table fields.  I have the attribute table fields all setup the way I want for one of the shapefiles.  I want to copy this attribute table setup over to the other shapefiles.  The entries of the tables are all empty for now, I just want to use the same columns/fields for all the shapefiles.  How can I copy the attribute table into the remaining shapefiles?  Using ArcInfo 10.0

0 Kudos
13 Replies
KeithAddison1
Frequent Contributor

Well this is baffling, here is the code I run:

import arcpy, time

arcpy.env.workspace = r'C:\Users\keith.addison\Documents\PythonStuff'

arcpy.env.overwriteOutput = True

template = 'ParcelDataAC150.shp'

fcs = arcpy.ListFeatureClasses('*Copy*')

starttime1 = time.time()

outCounter = 1

for fc in fcs:

    newCopy = "output_" + str(outCounter) + '.shp'

    arcpy.Copy_management(template, newCopy)

    arcpy.Append_management(fc, newCopy, 'NO_TEST')

    outCounter += 1

endtime1 = time.time() - starttime1

print 'Total time: ' + str(endtime1) +'s'

And it doesn't create any new shapefiles in the working directory or anywhere else, it also outputs the run time as 0.0s.  I've tried running it with several different template shapefiles with varying populated and unpopulated field setups to no avail.

0 Kudos
DarrenWiens2
MVP Honored Contributor

You've got your template and "other" shapefiles. In my example, my "other" shapefiles happened to have the word "Copy" in their file names. Do yours? The line fcs = arcpy.ListFeatureClasses('*Copy*') means find the feature classes with the word "Copy" in the file name. Do you have any such shapefiles?

0 Kudos
KeithAddison1
Frequent Contributor

That was it, thanks!  Sorry about that, I'm still figuring out Python syntax.

0 Kudos
DarrenWiens2
MVP Honored Contributor

You could:

1.) Copy your template shapefile

2.) Append the features from one of 20 shapefiles to the copy (Schema type = NO_TEST)

...and repeat.