Click here to Skip to main content
15,168,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application that when it opens it checks a remote server and copies the contents to the local machine. To save time i need to compare the local and remote files and if the remote files are updated then i need to copy them to the machine and if the local machine has files that the remote server dosent have then i need to delete them from the local machine.

the code i have been trying to use to compare files only letes me do a file. Help would be great.


Function to Find the Latest File

Sub Exec_Get_Latest_File()

File1 = "c:\temp\Sample.txt"
File2 = "c:\temp\Sample1.txt"

MsgBox "The LatestFile is " & Get_Latest_File(File1, File2)

End Sub

Function Get_Latest_File(ByVal sFile1 As String, ByVal sFile2 As String) As String

Dim DateFile1 As Date
Dim DateFile2 As Date

DateFile1 = FileDateTime(sFile1)
DateFile2 = FileDateTime(sFile2)

If DateDiff("s", DateFile1, DateFile2) = 0 Then
Get_Latest_File = "Both Files are Modified at the same time"
ElseIf DateDiff("s", DateFile1, DateFile2) <>
Get_Latest_File = sFile1
Get_Latest_File = sFile2
End If

End Function

1 solution

Comparing files based on creation date is not good idea, because date on the local computer can be differ on the server. Better way is to compare the content of files using MD5[^] hash algoritm. Here you have few examples:[^][^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900