File Compare (Data Management)

License Level:BasicStandardAdvanced

Summary

Compares two files and returns the comparison results. File Compare can report differences between two ASCII files or two binary files.

Usage

Syntax

FileCompare_management (in_base_file, in_test_file, {file_type}, {continue_compare}, {out_compare_file})
ParameterExplanationData Type
in_base_file

The Input Base File is compared with the Input Test File. The Input Base File refers to afile that you have declared valid. This base file has the correct content and information.

File
in_test_file

The Input Test File is compared against the Input Base File. The Input Test File refers to afile that you have made changes to by editing or compiling new information.

File
file_type
(Optional)

The type of files being compared.

  • ASCIICompare using ASCII characters. This is the default.
  • BINARYPerform a binary compare.
String
continue_compare
(Optional)

Indicates whether to compare all properties after encountering the first mismatch.

  • NO_CONTINUE_COMPAREStops after encountering the first mismatch. This is the default.
  • CONTINUE_COMPARECompares other properties after encountering the first mismatch.
Boolean
out_compare_file
(Optional)

This file will contain all similarities and differences between the Input Base File and the Input Test File. This file is a comma-delimited text file which can be viewed and used as a table in ArcGIS.

File

Code Sample

FileCompare example (Python Window)

The following Python window script demonstrates how to use the FileCompare function in immediate mode.

import arcpy
arcpy.FileCompare_management(r'C:/Workspace/well_xycoordinates.txt', r'C:/Workspace/new_well_coordinates.txt', 'ASCII', 'CONTINUE_COMPARE', r'C:/Workspace/well_file_compare.txt' )
FileCompare tool example (Stand-alone script)

Example of how to use the FileCompare tool in a stand-alone script.

# Name: FileCompare.py
# Description: Compare two text files and return comparison result.
# Author: ESRI

# import system modules 
import arcpy

try:
    # Set local variables
    base_file= "C:/Workspace/well_xycoordinates.txt"
    test_file= "C:/Workspace/new_well_coordinates.txt"
    file_type = "ASCII"
    continue_compare = "CONTINUE_COMPARE"
    compare_file = "C:/Workspace/well_file_compare.txt"
 
    # Process: FeatureCompare
    compare_result = arcpy.FileCompare_management(base_file, test_features, file_type, continue_compare, compare_file)
    print compare_result
    print arcpy.GetMessages()
 
except:
    # Print error message if an error occurs
    print arcpy.GetMessages()

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015