我試圖讓這個腳本工作。 它基本上應該鏡像兩組文件夾,並確保它們完全相同。如果文件夾丟失,應複製文件夾及其內容。Vbscript - 檢查每個子文件夾的文件和複製文件
然後,腳本應該比較DateModified屬性,並且只在源文件比目標文件新時才複製文件。
我想在一起做一個腳本,完全是。到目前爲止,我已經能夠檢查所有子文件夾,如果它們存在,然後創建它們,如果它們不存在。 然後,我已經能夠掃描頂級源文件夾中的文件,並將它們複製(如果它們不存在或者如果DateModified屬性在源文件上更新)。
剩下的是基本上掃描每個子文件夾的文件,並複製它們,如果它們不存在或如果DateModified郵票是新的。
下面的代碼:
Dim strSourceFolder, strDestFolder
strSourceFolder = "c:\users\vegsan\desktop\Source\"
strDestFolder = "c:\users\vegsan\desktop\Dest\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objTopFolder = fso.GetFolder(strSourceFolder)
Set colTopFiles = objTopFolder.Files
'Check to see if subfolders actually exist. Create if they don't
Set objColFolders = objTopFolder.SubFolders
For Each subFolder in objColFolders
CheckFolder subFolder, strSourceFolder, strDestFolder
Next
' Check all files in first top folder
For Each objFile in colTopFiles
CheckFiles objFile, strSourceFolder, strDestFolder
Next
Sub CheckFolder (strSubFolder, strSourceFolder, strDestFolder)
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folderName, aSplit
aSplit = Split (strSubFolder, "\")
UBound (aSplit)
If UBound (aSplit) > 1 Then
folderName = aSplit(UBound(aSplit))
folderName = strDestFolder & folderName
End if
If Not fso.FolderExists(folderName) Then
fso.CreateFolder(folderName)
End if
End Sub
Sub CheckFiles (file, SourceFolder, DestFolder)
Set fso = CreateObject("Scripting.FileSystemObject")
Dim DateModified
DateModified = file.DateLastModified
ReplaceIfNewer file, DateMofidied, SourceFolder, DestFolder
End Sub
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 Not fso.FileExists(destFileName) Then
fso.CopyFile sourceFile, destFileName
End if
if fso.FileExists(destFileName) Then
Set objDestFile = fso.GetFile(destFileName)
DestDateModified = objDestFile.DateLastModified
if DateModified <> DestDateModified Then
fso.CopyFile sourceFile, destFileName
End if
End if
End Sub