我真的不知道这里有什么不对。 我正在尝试创建一个vbscript,它基本上检查两个文件夹的文件并比较每个文件的DateLastModified属性,然后如果源文件的DateLastModified比现有文件更新,则将源文件复制到目标文件夹。
我有这段代码:
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
我得到错误:在第34行,Char 3“需要对象:'objDestFile' 但objDestFile是否已创建?
答案 0 :(得分:2)
您需要使用set eg。:
Set objDestFile = fso.GetFile(destFileName)