VBS对比更新游戏
Option Explicit
'URL:http://www.ganhui0818.cn
Dim SDir, LDir, MandatoryUpdate, DelRedundantFile, CompareSubFolder, MandatoryUpdateFolder
Dim ExcludedFolder, MandatoryUpdateFile, ExcludedFile, DiffTime, RunFile, RegFile, SystemFile
'远程目录
SDir = "\\gameserver\d\xiuxian\qq2008"
'本地目录
LDir = "f:\Documents and Settings\Administrator\桌面\新建文件夹2"
'是否强制更新所有文件(不对比,直接设所有文件为需更新状态),是=True,否=False,下同
MandatoryUpdate = False
'文件差异时间在此值内则不更新(单位:秒),建议设为3秒,强制更新所有文件时,勿略此设置
DiffTime = 3
Dim sobjFSO
Set sobjFSO = CreateObject("Scripting.FileSystemObject")
If Not CheckFolder(SDir,False) Then
Msgbox "远程目录" & Chr(34) & SDir & Chr(34) & "不存在,请确认!",64,"提示"
WScript.Quit
End If
Dim StartTime
StartTime = Now
ShowFolder SDir,LDir,DiffTime,MandatoryUpdate
Msgbox "耗时:" & Datediff("s",StartTime,Now) & "秒"
Function CheckFolder(strFolder,blnCreate)
If Not sobjFSO.FolderExists(sobjFSO.GetDriveName(strFolder)) Then
CheckFolder = False
Exit Function
End If
If Not sobjFSO.FolderExists(strFolder) And blnCreate Then
If CheckFolder(sobjFSO.GetParentFolderName(strFolder),blnCreate) Then
On Error Resume Next
sobjFSO.CreateFolder strFolder
If Err Then
CheckFolder = False
Err.Clear
On Error GoTo 0
Exit Function
Else
CheckFolder = True
End If
On Error GoTo 0
Else
CheckFolder = False
End If
Elseif Not sobjFSO.FolderExists(strFolder) And Not blnCreate Then
CheckFolder = False
Else
CheckFolder = True
End If
End Function
Function ShowFolder(Folder1,Folder2,intTimes,blnMandatory)
Dim objF, objFLs, objFL
Set objF = sobjFSO.GetFolder(Folder1)
Set objFLs = objF.SubFolders
ScanFile Folder1,Folder2,intTimes,blnMandatory
For Each objFL in objFLs
ShowFolder objFL.Path,Replace(objFL.Path,Folder1,Folder2,1,1,1),intTimes,blnMandatory
Next
End Function
Function ScanFile(Folder1,Folder2,intTimes,blnMandatory)
If Not CheckFolder(Folder2,True) Then Exit Function
Dim objF, objFIs, objFI, objTmpF
Set objF = sobjFSO.GetFolder(Folder1)
Set objFIs = objF.Files
For Each objFI In objFIs
If Not sobjFSO.FileExists(Replace(objFI.Path,Folder1,Folder2,1,1,1)) or blnMandatory Then
objFI.Copy Replace(objFI.Path,Folder1,Folder2,1,1,1)
Else
Set objTmpF = sobjFSO.GetFile(Replace(objFI.Path,Folder1,Folder2,1,1,1))
If objFI.Size <> objTmpF.Size or Abs(DateDiff("s",objFI.DateLastModified,objTmpF.DateLastModified)) >= intTimes Then
objFI.Copy Replace(objFI.Path,Folder1,Folder2,1,1,1)
End If
End If
Next
End Function
页:
[1]