SocketTools .NET Edition

FileEncoder.CompareFile Method (String, String, Boolean)

Compares the contents of two files and their modification times.

[Visual Basic]
Overloads Public Function CompareFile( _
   ByVal fileName1 As String, _
   ByVal fileName2 As String, _
   ByVal compareTime As Boolean _
) As Boolean
[C#]
public bool CompareFile(
   string fileName1,
   string fileName2,
   bool compareTime
);

Parameters

fileName1
A string which specifies the name of the first file to compare.
fileName2
A string which specifies the name of the second file to compare.
compareTime
A boolean value which specifies if the file modification times for both files should be compared.

Return Value

A boolean value which specifies if the file contents are identical and optionally if the file modification times are the same.

Remarks

It is permitted to use environment variables in a file name by surrounding the variable name with the percent symbol. If the file name contains any leading or trailing space characters after the variable expansion, they will be removed. The file must exist and the current process must have permission to read the contents of the file.

This method will normalize the file names and perform checks to make sure the names do not contain illegal characters. If the name includes quotes, wildcard characters or other invalid symbols the method will fail and with the last error code set to errorInvalidFileName. It is permitted to use forward slashes in path names and these will be converted to the standard backslash character used with Windows paths. This method cannot be used to compare the contents of NTFS alternate data streams.

If the compareTime parameter is true, the comparison will only succeed if the contents are identical and both files have the same last modification time. If this parameter is false, the file modification times are ignored.

See Also

FileEncoder Class | SocketTools Namespace | FileEncoder.CompareFile Overload List | CompareFile | CompressFile | ExpandFile