Reputation: 675
I have this script but would like to expand it to check a list of files and also existence of mapped drive R: and map if not there.
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
The snippet does not work if not drive not there with an error “this network connection does not exist” but remaps ok.
> Set WSHNetwork = CreateObject("WScript.Network")
>
> WSHNetwork.RemoveNetworkDrive "R:","True","True"
>
> WSHNetwork.MapNetworkDrive "R:", "\\192.168.1.103\","True"
Upvotes: 1
Views: 619
Reputation: 42182
don't map, do the comparison directly with the url
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
Upvotes: 1