Summary
Compares two files and returns the comparison results. File Compare can report differences between two ASCII files or two binary files.
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.
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
- "#"—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.
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.
Syntax
FileCompare_management (in_base_file, in_test_file, {file_type}, {continue_compare}, {out_compare_file})
Parameter | Explanation | Data 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.
| String |
continue_compare (Optional) | Indicates whether to compare all 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.
# 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 Exception as err:
print(err.args[0])
Environments
This tool does not use any geoprocessing environments
Licensing information
- ArcGIS Desktop Basic: Yes
- ArcGIS Desktop Standard: Yes
- ArcGIS Desktop Advanced: Yes