comparing two files

iramirezs used Ask the Experts™
i need know with code .vbs how to compare two files  

file1 is on c:\datos\online.mde
file2 is on   \\server2k\update\online.mde

if the date created of the file2 is > file1
     copy the file2 on file1

sorry my english is very bad.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
   Dim ofs As Scripting.FileSystemObject
    Set ofs = New Scripting.FileSystemObject
    Dim sFile2 As String
    Dim sFile1 As String
    sFile2 = "\\server2k\update\online.mde"
    sFile1 = "c:\datos\online.mde"
    If ofs.GetFile(sFile2).DateCreated > ofs.GetFile(sFile1).DateCreated Then
        ofs.CopyFile sFile2, sFile1, True
    End If
You must add a reference to the Microsfot Scripting Runtime for this to work

Scripting is all new to me. It looks really interesting.

Just wondering, couldn't you use built-in functions in VB to do this? Like:

If FileDateTime(file2) > FileDateTime(file1) then
   FileCopy file2, file1

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I suppose you could, but I'm not sure if it will take UNCs as indicated in the question.  I'm not sure it won't, but since I'm fairly certain I have used the FSO with UNCs..  I'm going to try the FileDateTime on a UNC when I get into work.  Will let you know.

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- Assign the points to twalgrave
Please leave any comments here within the
next seven days.
Per recommendation, force-accepted.

EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial