Vbscript - Compare and copy files from folder if newer than destination files

Posted by Kenny Bones on Stack Overflow See other posts from Stack Overflow or by Kenny Bones
Published on 2010-05-14T07:53:32Z Indexed on 2010/05/14 8:04 UTC
Read the original article Hit count: 328

Hi, I'm trying to design this script that's supposed to be used as a part of a logon script for alot of users. And this script is basically supposed to take a source folder and destination folder as basically just make sure that the destination folder has the exact same content as the source folder. But only copy if the datemodified stamp of the source file is newer than the destination file.

I have been thinking out this basic pseudo code, just trying to make sure this is valid and solid basically.

Dim strSourceFolder, strDestFolder
strSourceFolder = "C:\Users\User\SourceFolder\"
strDestFolder = "C:\Users\User\DestFolder\"

For each file in StrSourceFolder
     ReplaceIfNewer (file, strDestFolder)
Next

Sub ReplaceIfNewer (SourceFile, DestFolder)

    Dim DateModifiedSourceFile, DateModifiedDestFile
    DateModifiedSourceFile = SourceFile.DateModified()
    DateModifiedDestFile = DestFolder & "\" & SourceFile.DateModified()

    If DateModifiedSourceFile < DateModifiedDestFile
        Copy SourceFile to SourceFolder
    End if

End Sub

Would this work? I'm not quite sure how it can be done, but I could probably spend all day figuring it out. But the people here are generally so amazingly smart that with your help it would take alot less time :)

© Stack Overflow or respective owner

Related posts about vbscript

Related posts about compare