File Compare (Data Management)

Summary

Compares two files and returns the comparison results..

Usage

  • This tool returns messages showing the comparison result. By default, it will stop executing after encountering the first miscompare. To report all differences, check on the Continue Comparison parameter.

  • File Compare can report differences between two ASCII files or two binary files

  • This tool supports masking out of characters, words, and lines of text in an ASCII file. For example, files may be identical except they may contain text representing date and time of creation. Thus, the files would 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. The SunOS platform may report a value of 415.999999999, while the Windows XP platform reports 416.000000000. To handle false character comparisons, File Compare provides several masking capabilities. Before comparing new text files with existing base files, edit the base files to include these special masking symbols.

    • "#"—The simplest masking symbol is the "#" symbol. Wherever a # 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
    • "??"—Another masking tool is the "??" symbol combination. To mask out an entire "word", add "??" at the beginning of it.
      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. An obvious example of this would be the name of a file with an extension—streetnames.dbf. There could be instances where you would want part of the name, either before or after the '.', to be ignored in the comparison of the token.
      Base: Master table is: streetnames?!.dbf
      Test: Master table is: streetnames
    • "???"—This allows you to mask the entire line following it.
      Base: ???       8       4       1       0      14      10
      Test:        12      8      2       1      16     12
  • ASCII is the default file type. If entering binary files, change the file type to Binary (BINARY in Python).

  • When ASCII files miscompare, it will report differences, such as the total number of characters are different and report the differences for each line.

  • When binary files miscompare, it will report that the file sizes are different and report the differences for each byte.

  • The Output Compare 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.

  • When using this tool in Python, you can get the status of this tool using result.getOutput(1). The value will be 'true' when no differences are found and 'false' when differences are detected.

    Learn more about using tools in Python

Parameters

LabelExplanationData Type
Input Base File

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

File
Input Test File

The Input Test File is compared against the Input Base File. The Input Test File refers to a file 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 Comparison
(Optional)

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

  • Unchecked—Stops after encountering the first mismatch. This is the default.
  • Checked—Compares other properties after encountering the first mismatch.

Boolean
Output 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

Derived Output

LabelExplanationData Type
Compare Status

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

Boolean

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

The Input Base File is compared with the Input Test File. The Input Base File refers to a file 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 a file 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

Derived Output

NameExplanationData Type
compare_status

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

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.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 example 2 (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.

# 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.FileCompare_management(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.

Related topics