File Compare (Data Management)

Summary

Compares two files and returns the comparison results.

Usage

  • This tool returns messages showing the comparison result. By default, the tool will stop running after encountering the first difference between the inputs. To report all differences, check the Continue Comparison parameter.

  • If the differences reported between the input datasets are due to the addition or deletion of records, only the first reported difference is valid. All reported differences after the addition or deletion will be due to the comparison being out of sequence. The compare tools do not attempt to find the next set of matching records after an added or deleted record is encountered.

  • This tool can report differences between two ASCII files or two binary files

  • This tool supports masking of characters, words, and lines of text in an ASCII file. For example, two files may be identical except that they contain text representing the date and time of creation. This difference would result in a miscompare. In addition, small variations occur in the way that each platform stores or manipulates numbers. This leads to differences in numeric precision among platforms. To handle false character comparisons, this tool provides several masking capabilities. Before comparing new text files with existing base files, edit the base files to include these special masking symbols.

    • "#"—Wherever the "#" symbol appears in the input base file, the corresponding character in the input test file will be ignored.
      Base: Y delta = 9048.6#
      Test: Y delta = 9048.61
    • "??"—To mask out an entire word, add "??" at the beginning of the word.
      Base: Processing ??ESRI1/ARCIGDS/TESTRUN/CONV/ARCIGDS/CPXSHAPE.DGN
      Test: Processing ESRI2/ARCIGDS/TESTRUN/CONV/ARCIGDS/CPXSHAPE2.DGN
    • "?!"—A single token may have a period (.) imbedded in it. For example, for the name of a file with an extension of streetnames.dbf, there may be instances where you want part of the name, either before or after the period (.), to be ignored in the comparison of the token.
      Base: Master table is: streetnames?!.dbf
      Test: Master table is: streetnames
    • "???"—Mask the entire line following the ??? characters.
      Base: ???       8       4       1       0      14      10
      Test:        12      8      2       1      16     12
  • ASCII is the default file type. When using binary files as input, change the File Type parameter to Binary.

  • When there is a miscompare between ASCII files, the tool will report differences, such as the total number of characters that are different and the differences for each line.

  • When there is a miscompare between binary files, the tool will report that the file sizes are different and report the differences for each byte.

  • The Output Compare File parameter value will contain all similarities and differences between the Input Base File and the Input Test File parameter values. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

  • When using this tool in Python, get the status of the comparison from the returned Result object using the index position of 1.(result[1]). The value will be 'true' when no differences are found and 'false' when differences are found.

    Learn more about using tools in Python

Parameters

LabelExplanationData Type
Input Base File

The file that will be compared with the Input Test File parameter value. This parameter value is a file that you have declared valid. This base file has the correct content and information.

File
Input Test File

The file that will be compared with the Input Base File parameter value. This parameter value is a file that you have made changes to by editing or compiling new information.

File
File Type
(Optional)

Specifies the type of comparison that will be used for the files.

  • ASCIIThe files will be compared using ASCII characters. This is the default.
  • BinaryThe files will be compared using a binary compare.
String
Continue Comparison
(Optional)

Specifies whether the comparison will continue after encountering the first difference between the inputs.

  • Unchecked—The tool will stop after encountering the first difference. This is the default.
  • Checked—The tool will continue after encountering the first difference.

Boolean
Output Compare File
(Optional)

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

File

Derived Output

LabelExplanationData Type
Compare Status

The compare status will be 'true' when no differences are found and 'false' when differences are found.

Boolean

arcpy.management.FileCompare(in_base_file, in_test_file, {file_type}, {continue_compare}, {out_compare_file})
NameExplanationData Type
in_base_file

The file that will be compared with the in_test_file parameter value. This parameter value is a file that you have declared valid. This base file has the correct content and information.

File
in_test_file

The file that will be compared with the in_base_file parameter value. This parameter value is a file that you have made changes to by editing or compiling new information.

File
file_type
(Optional)

Specifies the type of comparison that will be used for the files.

  • ASCIIThe files will be compared using ASCII characters. This is the default.
  • BINARYThe files will be compared using a binary compare.
String
continue_compare
(Optional)

Specifies whether the comparison will continue after encountering the first difference between the inputs.

  • NO_CONTINUE_COMPAREThe tool will stop after encountering the first difference. This is the default.
  • CONTINUE_COMPAREThe tool will continue after encountering the first difference.
Boolean
out_compare_file
(Optional)

The output file that will contain all similarities and differences between the inputs. This file is a comma-delimited text file that can be viewed and used as a table in ArcGIS.

File

Derived Output

NameExplanationData Type
compare_status

The compare status will be 'true' when no differences are found and 'false' when differences are found.

Boolean

Code sample

FileCompare example 1 (Python window)

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

import arcpy
arcpy.management.FileCompare(
    r'C:/Workspace/well_xycoordinates.txt', 
    r'C:/Workspace/new_well_coordinates.txt', 'ASCII', 'CONTINUE_COMPARE', 
    r'C:/Workspace/well_file_compare.txt')
FileCompare example 2 (stand-alone script)

The following example demonstrates how to use the FileCompare function in a stand-alone script.

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

# Import system modules 
import arcpy

# 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.management.FileCompare(base_file, test_features, 
                                              file_type, continue_compare, 
                                              compare_file)
print(compare_result)
print(arcpy.GetMessages())

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics