0

I have function to check whether the two files are similar or not. So one thing I did is comparing the sizes of files. I am looking for a way to compare contents of files and get a match percentage. Depending on the percentage value I can decide whether they are mostly equal or not?

If it is text file, I am reading the text and computing the difference. But what if it is a excel or any other file which have images like that??

Rupesh
  • 983
  • 3
  • 11
  • 20
  • Can you define what you mean by "similar"? – lurker Aug 23 '13 at 12:18
  • If you open an Excel file (or a pdf or any other file type with complex/encrypted contents) you would just get a bunch or weird symbols with no meaning. You can apply these ideas only to files suitable to be (directly) converted to .txt files. Or, logically, rely on the corresponding API (one for Excel, another one for pdf, another one for , etc.) – varocarbas Aug 23 '13 at 12:28
  • There's ome great questions http://stackoverflow.com/questions/9065536/text-comparison-algorithm about comparing two text files. It will be very difficult to compare binary file cause you'll never know how to process the information. – the_lotus Aug 23 '13 at 17:13

1 Answers1

0

You could try something like this and then make a decision based off comparision of the 2 files.

Imports System.IO

Public Class FileSizeChecker

Public Sub FileChecker()

    Dim info As New FileInfo("test.txt")

    ' Get length of the file.
    Dim length As Long = info.Length

    ' Add more characters to the file.
    File.AppendAllText("test.txt", " More characters.")

    ' Get another file info.
    ' ... Then get the length.
    Dim info2 As New FileInfo("test.txt")
    Dim length2 As Long = info2.Length

    ' Show how the size changed.
    Console.WriteLine("Before and after: {0}, {1}", length, length2)
    Console.WriteLine("Size increase: {0}", length2 - length)

End Sub
Adam
  • 490
  • 7
  • 21