• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

How to Compare files in two directories.

my First attempt simply used the last modifided date from FileInfo.
The problem I am having is one set of files were installed using InstallShield and for some reason the modification times vary by a second or two on copies of the exact same file.
Is there an better (Quick) way to compare files. I don't want to have to open and read the files. This needs to be fast.
0
MCofer
Asked:
MCofer
  • 5
  • 3
  • 2
  • +1
1 Solution
 
strickddCommented:
If you are just trying to write a utility to do this here is a pretty good one: http://www.grigsoft.com/wincmp.htm.

If you need it in your code, you can:


Dim stream1 As New System.IO.StreamReader(Path)
        Dim stream2 As New System.IO.StreamReader(Path2)

        Dim string1 As String = stream1.ReadToEnd()
        Dim string2 As String = stream2.ReadToEnd()

        If (string1 = string2) Then
            'they are equal
        Else
            'they are different
        End If
0
 
ctm5Commented:
The only way I have found is to throw each into a stream reader, read into a string, and then see if the strings are equal. You can turn on Option Compare Binary to speed up reading the files.

I know you said you didn't want to have to open and read the files, but I searched for quite a long time trying to find a different way, and had no luck. Anyone?

ctm5
0
 
ctm5Commented:
oooh, strickdd, we came to the same conclusion!

ctm5
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
strickddCommented:
Yeah, you were just a minure behind:)
0
 
strickddCommented:
*minute
0
 
MCoferAuthor Commented:
My problem is one set of files is on the users local machine and the other is on the network (VPN).
The users are scatterted all over the world and are often on very slow connections.
My idea was to create an XML file(updated each time a file changes) with  fileInfo.LastWriteTime so the user did not actually need to search the network server.
Is it possible to write a hash or maybe file checksum to an XML file. Opening each nework file just takes to long.
0
 
strickddCommented:
Yeah, you can open a streamreader and get the hash code and compare those.

Dim stream1 As New System.IO.StreamReader(Path)
        Dim stream2 As New System.IO.StreamReader(Path2)

        Dim Hash1 as Integer =  = stream1.ReadToEnd().GetHashCode()
        Dim Hash2 As Integer = stream2.ReadToEnd().GetHashCode()

        If (Hash1 = Hash2) Then
            'they are equal
        Else
            'they are different
        End If
0
 
ctm5Commented:
So you can do what you want -- store the hash in an XML file on the server. It will have to be updated everytime someone changes the file, of course, and you could run into concurrancy issues.

ctm5
0
 
anyoneisCommented:
Why are you comparing the files? Are you trying to keep everyone in sync? Could you possibly use ClickOnce deployment for these files and let that take care of the versioning?

David
0
 
strickddCommented:
Another option you have is to run: http://www.download.com/XCopy-Net/3000-2248_4-10483581.html?tag=lst-0-2. You can make sure that the newest file is in a specific location. It might be worth your trouble. It is a little buggy when saving your settings, but otherwise it is pretty quick, efficient, and FREE
0
 
MCoferAuthor Commented:
Thanks to everyone for the help
The XCopy freeware was close to what I actually needed.
The Hash would be to slow to use over the network but storing the hash in an XML worked fine.

Again Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now