Skip To Content

Generate Attachment Match Table

Usage

  • This tool will go through each row for the input target dataset and compare the Key Field in this dataset to the names of files in the Input Folder. For each match that occurs, a record will be created in the output table that contains the ObjectID value from the Input Dataset and the name of the matched file (or optionally the full path to that file). When used in the Add Attachments and Remove Attachments tools the MATCHID field is used as the key field to link the files on disk to records in the input dataset.

  • If the Output Match Table location is a folder, the output can be created as a dBASE table by specifying a name with the extension .dbf, or can be created as an INFO table by specifying a name with no extension. If the output location is a geodatabase, the match table will be a geodatabase table (do not specify an extension).

Syntax

GenerateAttachmentMatchTable_management (in_dataset, in_folder, out_match_table, in_key_field, {in_file_filter}, {in_use_relative_paths})
ParameterExplanationData Type
in_dataset

Input dataset that contains records that will have files attached.

Table View
in_folder

Folder that contains files to attach.

Folder
out_match_table

Table that will be generated which contains two columns: MATCHID and FILENAME.

Table
in_key_field

The values in this field will match the names of the files in the input folder. The matching behavior will ignore file extensions, which allows multiple files with various file extensions to match with a single record in the input dataset.

For example, if the input Key Field value is lot5986, a file on disk named lot5986.jpg would match with this record.

Field
in_file_filter
(Optional)

This parameter is used to limit the files the tool considers for matching. If the file name does not meet the criteria in the file filter parameter it will not be processed and therefore will not show up in the output match table. Wild cards (*) can be used in this parameter for more flexible filtering options. Multiple semicolon-delimited filters can be used as well.

For example, consider a directory that contains the following files: parcel.tif, parcel.doc, parcel.jpg, houses.jpg, and report.pdf.

To limit the possible matches in this list to .jpg files, use *.jpg.

To limit the possible matches in this list to .pdf and .doc files, use *.pdf; *.doc.

To limit the possible matches in this list to files beginning with parcel, use parcel*.

To limit the possible matches in this list to files that contain the text arc, use *arc*.

String
in_use_relative_paths
(Optional)

Determines if the output match table field FILENAME will contain a full path to the dataset or only the file name.

  • RELATIVEThe output FILENAME field will contain relative paths. This is the default.
  • ABSOLUTEThe output FILENAME field will contain full paths to the data.
Boolean

Code sample

GenerateAttachmentMatchTable example (Python window)

The following code snippet demonstrates how to use the GenerateAttachmentMatchTable in the Python window.

import arcpy
arcpy.GenerateAttachmentMatchTable_management("C:/data/parcels.gdb/parcels",
                                              "C:/attachment_folder",
                                              "C:/data/temp.gdb/matchtable",
                                              "AttachmentKeyField",
                                              "*.jpg; *.pdf",
                                              "ABSOLUTE")
GenerateAttachmentMatchTable example (stand-alone Python script)

The following stand-alone script demonstrates how to use the GenerateAttachmentMatchTable tool to create a match table that contains matches for only JPG and PDF files.

# Name: GenerateAttachmentMatchTable_Example.py
# Description: Creates an attachment match table for all files that contain the string
#             'property' and are of type 'jpg' while looping through multiple folders.

# Import system modules
import arcpy, os

# Set local variables.
rootFolder = 'c:/work/'

for folder in os.walk(rootFolder):
    if folder[0].find('.gdb') == -1: #exclude file geodatabases from the folder list.
        arcpy.GenerateAttachmentMatchTable_management("C:/data/parcels.gdb/parcels",
                                                      folder[0],
                                                      "C:/data/temp.gdb/matchtable",
                                                      "AttachmentKeyField",
                                                      "*property*.jpg",
                                                      "RELATIVE")

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • ArcGIS Desktop Basic: No
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics