我有这个脚本,但想扩展它以检查文件列表以及是否存在映射驱动器R:并且如果不存在则映射。
FileA.txt
FileB.txt
FileD.txt
FileE.txt
FileF.dll
FileG.dll
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLocalFile = objFSO.GetFile("C:\SCRIPT\SCRIPTTEXT.txt")
dtmLocalDate = objLocalFile.DateLastModified
Set objServerFile = objFSO.GetFile("R:\SCRIPT\SCRIPTTEXT.txt")
dtmServerDate = objServerFile.DateLastModified
If dtmLocalDate < dtmServerDate Then
objFSO.CopyFile objServerFile.Path, objLocalFile.Path, OverwriteExisting
End If
如果没有驱动器没有错误“此网络连接不存在”,则该代码段不起作用,但重新映射正常。
> Set WSHNetwork = CreateObject("WScript.Network")
>
> WSHNetwork.RemoveNetworkDrive "R:","True","True"
>
> WSHNetwork.MapNetworkDrive "R:", "\\192.168.1.103\","True"
答案 0 :(得分:1)
不要映射,直接与网址进行比较
on error resume next
path = "\\192.168.1.103\SCRIPT\SCRIPTTEXT.txt"
if objFSO.fileExist(path)
Set objServerFile = objFSO.GetFile(path)
dtmServerDate = objServerFile.DateLastModified
if dtmLocalDate < dtmServerDate Then
objFSO.CopyFile objServerFile.Path, objLocalFile.Path, OverwriteExisting
end if
else
objFSO.CopyFile objServerFile.Path, objLocalFile.Path
end if