


This version checks for the file, and creates the desired copy (with a specific date as part of the name, which can be modified to read the system date).
I've removed all unnecessary variables and functions.
Dim oFSO, sCList, sComputer
Dim file
Const ForReading = 1
Const OverwriteExisting = True
'Get computers ——————————————–
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set sCList = oFSO.OpenTextFile("c:scriptsservers.txt")
Do Until sCList.AtEndOfStream
sComputer = sCList.ReadLine
msgbox(sComputer)
file = "" & sComputer & "d$ABCMy SystemTestConftest.txt"
If oFSO.FileExists(file) Then
msgbox("file exists")
oFSO.CopyFile file,replace(file,".txt","_20110907.txt")
else
msgbox("file doesn't exist")
end if
Loop
sCList.Close
WScript.Echo "Finished Updates on all computers"
This should serve as a starting point.
Please test it, and post back with any further questions or problems you encounter.
Hi Carlosdl,
So Adding the script, FSO.CopyFile “\\machine\d$\file.txt” “\\machine\d$\staging\file.txt” to the code below will allow me to move a copy of the file to the staging folder?
added copyfile statement to the script below;
Dim oFSO, sCList, sComputer
Dim file
Const ForReading = 1
Const OverwriteExisting = True
‘Get computers ——————————————–
Set oFSO = CreateObject(”Scripting.FileSystemObject”)
Set sCList = oFSO.OpenTextFile(”c:\scripts\servers.txt”)
Do Until sCList.AtEndOfStream
sComputer = sCList.ReadLine
msgbox(sComputer)
file = “\\” & sComputer & “\d$\ABCMy SystemTestConftest.txt”
If oFSO.FileExists(file) Then
msgbox(”file exists”)
oFSO.CopyFile file,replace(file,”.txt”,”_20110907.txt”)
else
FSO.CopyFile “\\machine\d$\file.txt” “\\machine\d$\staging\file.txt”
else
msgbox(”file doesn’t exist”)
end if
Loop
sCList.Close
WScript.Echo “Finished Updates on all computers”


Blackbird21, you tell us what you are trying to do, but you don’t mention the problems you are facing, nor the results you are getting.
The code you posted: does it (partially) work ? are you getting errors ?
Please, provide more details.
Thanks,
Thank you Carlosdl, sorry about that and one of the many errors that I was receiving was line 24/6 disk not ready I was also getting some errors about the placement of the next or if commands. I search the web in frustration to understand what this error exactly meant. The systems all have d drives and can be reach via D$ and are not fully. I have full admin permisisons on the drives as well. I’m sure there might be a better and cleaner script to use but I haven’t found one yet. Thank you.
If you can, please post the code inside of a {code} block. Regardless, at this point:
Do you really want a quote character before Set?
Tom
Dim oFSO, sCList, sComputer, sWinDir, colOperatingSystems, oOperatingSystem
Dim oWMIService, Error, sWinDirRaw, fso, drv, str
Const ForReading = 1
Const OverwriteExisting = True
‘Get computers ——————————————–
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
Set sCList = oFSO.OpenTextFile(“c:scriptsservers.txt”)
Do Until sCList.AtEndOfStream
sComputer = sCList.ReadLine
‘Get WinDir name ————————————————————
Set oWMIService = GetObject(“winmgmts:” & sComputer)
Set colOperatingSystems = oWMIService.InstancesOf(“Win32_OperatingSystem”)
For Each oOperatingSystem In colOperatingSystems
sWinDirRaw = oOperatingSystem.WindowsDirectory
sWinDir = StripDriveInfo(sWinDirRaw)
Next
‘If test.txt exists, make a backup copy named test_todaysdate.txt —————————————–
If oFSO.FileExists(“” & sComputer & “d$” & sWinDir & “ABCMy SystemTestConftest.txt”) Then
oFSO.CopyFile “” & sComputer & _
“d$” & sWinDir & “ABCMy SystemTestConftest.txt”, “” & sComputer & _
“d$” & sWinDir & “ABCMy SystemTestConftest_20110907.txt”
End If
‘Copy tests file —————————————————————
oFSO.CopyFile “d$ABCMy SystemTestConftest_20110907.txt”, “” & sComputer &_
“d$” & sWinDir & “ABCMy SystemTestConfstagingtest_20110907.txt”, OverwriteExisting
If Error <> 0 Then
WScript.Echo “Error copying file to ” & sComputer
Else
WScript.Echo “Finished script On ” & sComputer
WScript.Echo “———————————-”
End If
Loop
sCList.Close
WScript.Echo “Finished Updates on all computers”
MsgBox (“Exit?”)
Function StripDriveInfo(path)
‘Set fso = CreateObject(“Scripting.FileSystemObject”)
drv = oFSO.GetDriveName(path)
If Len(drv) >0 Then
str = Mid(path, Len(drv) + 2)
Else
str = path
End If
StripDriveInfo = str
End Function
Sorry for the late response.
I’m starting to look into this now.
I would start with a simplified version. Try this. It should display the list of servers in your input file. (Not all defined variables are used by now)
Dim oFSO, sCList, sComputer, sWinDir, colOperatingSystems, oOperatingSystem Dim oWMIService, Error, sWinDirRaw, fso, drv, str Const ForReading = 1 Const OverwriteExisting = True 'Get computers ——————————————– Set oFSO = CreateObject("Scripting.FileSystemObject") Set sCList = oFSO.OpenTextFile("c:scriptsservers.txt") Do Until sCList.AtEndOfStream sComputer = sCList.ReadLine msgbox(sComputer) Loop sCList.Close WScript.Echo "Finished Updates on all computers"I forgot to escape the backslashes (in the file path), and the editor ate them.
Also, the editor transforms single and double quotes, so make sure to correct them if you are copy-pasting the code.
Hi Carlosdl
Thank you for taking another look at the code and I’ll test the code today and post back the results. BB21
Hi Carlosdl,
The script works great and thank you for cleaning it up for me as well! Sorry it took so long to reply back!. I do have one other thing I would like the script to do and that is to now move a copy of the renamed file to a folder called stagging (ABCMy SystemTestConfstagingtest) that’s within the same directory. I’m still learning scripting but I tried using oFSO.CopyFile “d$ABCMy SystemTestConfstagingfile.txt” and received the error path not found.
Hi Carlosdl,
The script works great and thank you for cleaning it up for me as well! Sorry it took so long to reply back!. I do have one other thing I would like the script to do and that is to now move a copy of the renamed file to a folder called stagging (ABCMy SystemTestConfstagingtest) that’s within the same directory. I’m still learning scripting but I tried using oFSO.CopyFile “d$ABCMy SystemTestConfstagingfile.txt” and received the error path not found.
Hi Blackbird21. Sorry for the late response.
The CopyFile method takes 2 parameters, the source and target files (including path).
Something like this:
Correction:
Hi Carlosdl,
So Adding the script, FSO.CopyFile “\machined$file.txt” “\machined$stagingfile.txt” to the code below will allow me to move a copy of the file to the staging folder?
added copyfile statement to the script below;
Dim oFSO, sCList, sComputer
Dim file
Const ForReading = 1
Const OverwriteExisting = True
‘Get computers ——————————————–
Set oFSO = CreateObject(”Scripting.FileSystemObject”)
Set sCList = oFSO.OpenTextFile(”c:scriptsservers.txt”)
Do Until sCList.AtEndOfStream
sComputer = sCList.ReadLine
msgbox(sComputer)
file = “\” & sComputer & “d$ABCMy SystemTestConftest.txt”
If oFSO.FileExists(file) Then
msgbox(”file exists”)
oFSO.CopyFile file,replace(file,”.txt”,”_20110907.txt”)
else
FSO.CopyFile “\machined$file.txt” “\machined$stagingfile.txt”
else
msgbox(”file doesn’t exist”)
end if
Loop
sCList.Close
WScript.Echo “Finished Updates on all computers”