Script that will delete and replace a file in multiple locations
Hello I'm new to scripting and need a little assistance. I'm trying to write a vb script that will delete a file (same file name) in 2 locations and replace them with a file on a network share. Below is a script I believe that will work if it were just 1 file in 1 place. I'm guessing I would just need to add 2 more commands in to point to the 2nd location to be deleted and added?
Set objFSO = CreateObject("Scripting.FileSystemObject") ' File to be deleted. strFile = "C:\scripts\example2.txt" ' Source file. strSource = "\\MyServer\MyShare\example1.txt" ' Target location. strTarget = "c:\scripts" If (objFSO.FileExists(strFile) = True) Then obFSO.DeleteFile strFile, True End If ' Copy file. objFSO.CopyFile strSource, strTarget, True
Also there are some computers that won't have the file at all and I would like for it to ignore those. I'm not sure but I think if it's not there the script will fail and an error message will show up. Which I don't want since I'll be pushing this out to all the computers in our environment.
Any help is greatly appreciated. Thanks for your time!