I don't really know what's wrong right here.
I'm trying to create a vbscript that basically checks two Folders for their files and compare the DateLastModified attribute of each and then copies the source files to the destination folder if the DateLastModified of the source file is newer than the existing one.
I have this code:
Dim strSourceFolder, strDestFolder
Dim fso, objFolder, colFiles
strSourceFolder = "c:\users\user\desktop\Source\"
strDestFolder = "c:\users\user\desktop\Dest\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder(strSourceFolder)
Set colFiles = objFolder.Files
For each objFile in colFiles
Dim DateModified
DateModified = objFile.DateLastModified
ReplaceIfNewer objFile, DateModified, strSourceFolder, strDestFolder
Next
Sub ReplaceIfNewer (sourceFile, DateModified, SourceFolder, DestFolder)
Const OVERWRITE_EXISTING = True
Dim fso, objFolder, colFiles, sourceFileName, destFileName
Dim DestDateModified, objDestFile
Set fso = CreateObject("Scripting.FileSystemObject")
sourceFileName = fso.GetFileName(sourceFile)
destFileName = DestFolder & sourceFileName
if fso.FileExists(destFileName) Then
objDestFile = fso.GetFile(destFileName)
DestDateModified = objDestFile.DateLastModified
msgbox "File last modified: " & DateModified
msgbox "New file last modified: " & DestDateModified
End if
End Sub
And I get the error: On line 34, Char 3 "Object required: 'objDestFile'
But objDestFile IS created?