FileCmp
provides the function filecmp
, which returns true
if two files are equal byte by byte.
This code is adapted from an example in this Discourse post.
Only filecmp
is exported.
julia> using FileCmp
julia> filecmp("path1", "path2")
true
filecmp
is similar to the Python function
filecmp.cmp
but provides more information, as does the Unix/Linux/GNU
command cmp
.
filecmp(path1::AbstractString, path2::AbstractString, bufsize=0; info=Val(false); limit=0)
filecmp(io1::IO, io2::IO, bufsize=0; info=Val(false), limit=0)
- Return
true
ifpath1
andpath2
are equal byte by byte. Otherwise returnfalse
. - If either file does not exist an exception is thrown.
- If
info
istrue
, then return an instance ofFileCmp.Info
instead ofBool
. The instance ofFileCmp.Info
is then queried with functionsfiles_equal
,bytes_read
, andgot_eof
to get information similar to Unixcmp
. - The keyword argument
info
may be one oftrue
,false
,Val(true)
, orVal(false)
. The latter two are supported in case the application requires the return type to be inferrable. - If
limit
is greater than zero, then read at mostlimit
bytes. - The files are read into buffers of
bufsize
bytes. Ifbufsize=0
, then a default is used.
FileCmp.files_equal(info::FileCmp.Info)
Return true
if the files compared to produce info
are the byte-for-byte equal.
The following is always true:
filecmp(p1, p2; info=false) == files_equal(filecmp(p1, p2; info=true))
got_eof(info::FileCmp.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
.
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.