RE: Check if files equal

new topic     » topic index » view thread      » older message » newer message

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_000_01C22612.2AE20EC0
 charset=iso-8859-1

Here is a routine that might be useful to someone...

---------------
include file.e

-- Returns true (1) if the two files contain the same data, otherwise it
returns false (0)
-- Parameters: 
--    1: sequence : The path and name of a file
--    2: sequence : The path and name of another file
function fileEqual(sequence pFileA, sequence pFileB)
    integer lhA, lhB
    integer lcA, lcB
    object  ldA, ldB
    
    -- First check that they exist and that they are the same size.
    ldA = dir(pFileA)
    ldB = dir(pFileB)
    
    if atom(ldA) or atom(ldB) or ldA[1][D_SIZE] != ldB[1][D_SIZE] then
        return 0
    end if

    -- Now compare each byte, starting from the first byte.    
    lhA = open(pFileA, "rb")
    lhB = open(pFileB, "rb")
    
    lcA = 0
    lcB = 0

    -- Stop comparing as soon as a mismatch or EOF is found.    
    while lcA = lcB and lcA != -1 do
        lcA = getc(lhA)
        lcB = getc(lhB)
    end while

    close(lhA)
    close(lhB)

    -- if we end up with EOF in both files, they must be equal.        
    return (lcA = -1) and (lcB = -1)
    
end function    
-------------
Derek.

==================================================================
De informatie opgenomen in dit bericht kan vertrouwelijk zijn en 
is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht 
onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en 
de afzender direct te informeren door het bericht te retourneren. 
==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.


==================================================================

------_=_NextPart_000_01C22612.2AE20EC0
Content-Type: application/ms-tnef

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu