"""
Example: You have a folder of digital photographs of vacant homes; the photos
are named according to the ParcelID of the house in the picture. You'll
add these photos to a parcel feature class as attachments.
"""
import csv
import arcpy
import os
input = r"C:\Data\City.gdb\Parcels"
inputField = "ParcelID"
matchTable = r"C:\Data\matchtable.csv"
matchField = "ParcelID"
pathField = "Picture"
picFolder = r"C:\Pictures"
writer = csv.writer(open(matchTable, "wb"), delimiter=",")
writer.writerow([matchField, pathField])
for file in os.listdir(picFolder):
if str(file).find(".jpg") > -1:
writer.writerow([str(file).replace(".jpg", ""), file])
del writer
arcpy.EnableAttachments_management(input)
arcpy.AddAttachments_management(input, inputField, matchTable, matchField,
pathField, picFolder)