CompareFiles – Check whether two files contain the same data

CompareFiles – Check whether two files contain the same data

' compare two files' return True if they're equalFunction CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean    Dim fnum1 As Integer, isOpen1 As Boolean    Dim fnum2 As Integer, isopen2 As Boolean    Dim buffer1 As String, buffer2 As String    Dim bytesLeft As Long        ' size of the buffer - increase as needed    Const BUFFERSIZE = 10240        buffer1 = Space$(BUFFERSIZE)    buffer2 = buffer1        On Error GoTo ExitProc        ' compare the lengths    ' exit if not equal or if any error    bytesLeft = FileLen(file1)    If bytesLeft <> FileLen(file2) Then Exit Function        ' open the first file    fnum1 = FreeFile    Open file1 For Binary As #fnum1    isOpen1 = True        ' open the second file    fnum2 = FreeFile    Open file2 For Binary As #fnum2    isopen2 = True        ' read the entire files in chunks        Do While bytesLeft        ' don't read more than the residual bytes        If bytesLeft < Len(buffer1) Then            buffer1 = Space$(bytesLeft)            buffer2 = buffer1        End If            ' read a bunch of bytes from both files        Get #fnum1, , buffer1        Get #fnum2, , buffer2        ' exit if files don't match        If buffer1 <> buffer2 Then Exit Do            ' evaluate how many bytes are left to read        bytesLeft = bytesLeft - Len(buffer1)    Loop        ' if we get here because we read the entire    ' files, then the two files are equal    CompareFiles = (bytesLeft = 0)        ' flow through the error handler routine    ' to close files and exit    ExitProc:    If isOpen1 Then Close #fnum1    If isopen2 Then Close #fnum2    ' raise the error in the client code    If Err Then        Err.Raise Err.Number, , Err.Description    End IfEnd Function

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as