FileCmp.InfoType
Info

Information on result of filecmp(path1, path2; info=true), which compares the files path1 and path2 byte by byte.

Instances of this type may be queried by the functions files_equal, got_eof, and bytes_read.

Fields

  • byteindex::Int : 0 if no differing bytes were found. Otherwise the first index at which differing bytes were found.

  • sizecmp::Int : cmp(filesize(f1), filesize(f2))

  • bytesread::Int : number of bytes read from each file (not the sum from both files).

In particular, the files are the same, that is have exactly the same content, if and only if both _byte_index and _size_cmp are equal to zero.

FileCmp.bytes_readMethod
bytes_read(info::Info)

The number of bytes read from each file before either differing bytes were found, or EOF on one or both files.

FileCmp.filecmpFunction
filecmp(path1::AbstractString, path2::AbstractString, bufsize=0; info=Val(false); limit=0)
filecmp(io1::IO, io2::IO, bufsize=0; info=Val(false), limit=0)

Determine if files at path1 and path2 have the same content and optionally return information on how they differ. For info==false the return type is Bool. In this case, return true if files at path1 and path2 are equal byte by byte and false otherwise.

For info==true the return type is FileCmp.Info, which records at which byte index, if any, the files differ, and a comparison of the sizes of the files. (See FileCmp.Info). The result may be queried by the functions files_equal, got_eof, and bytes_read.

If path1 or path2 does not exist an exception is thrown.

The keyword argument info may be one of true, false, Val(true), or Val(false). The first two are more convenient. The latter two allow the return type to be inferred.

If limit is greater than zero, then read at most limit bytes.

The files are read into buffers of bufsize bytes. If bufsize=0, then a default is used.

Examples

Simplest use

using FileCmp
filecmp("file1", "file2")  # Return `true` or `false`

For more information do this

using FileCmp: filecmp, bytes_read, got_eof, files_equal
info_result = filecmp("file1", "file2"; info=true)
bytes_read(info_result) # how many bytes were read
got_eof(info_result) # Did we get eof on a file ? (see the docstring for got_eof)
files_equal(info_result) # are the files equal ?
FileCmp.files_equalMethod
files_equal(info::Info)

Return true if the files compared to produce info are the same.

The following is always true: filecmp(p1, p2; info=false) == files_equal(filecmp(p1, p2; info=true))

FileCmp.got_eofMethod
got_eof(info::Info)::Int

Return -1 if first file is a prefix of the second one. That is, an EOF occured on the first file, but not the second, and all compared bytes were equal. Return 1 if the reverse happened. Otherwise, return 0.