okay Guys
I'm trying to achieve the following objective.
I need to look for a file on a computer and if it is not there, I would like to look for it for x number of times using a For..Next loop and waiting for a specified amount of times between each iteration of the loop.
If the file is found, then it should go to another subroutine, which will move the file of the computer and if not, the script should move onto the next computer in the file.
My problem is the loop that should look for the file and then acting appropriately depending on whether the file was there or not. For starters, when the file is there, it is reporting as not being there and then the script bombs out without ever getting to the second hostname that has been read into a dictionary object from a file.
The code is as below:
Any help would be great to get this working. Cheers.
I'm trying to achieve the following objective.
I need to look for a file on a computer and if it is not there, I would like to look for it for x number of times using a For..Next loop and waiting for a specified amount of times between each iteration of the loop.
If the file is found, then it should go to another subroutine, which will move the file of the computer and if not, the script should move onto the next computer in the file.
My problem is the loop that should look for the file and then acting appropriately depending on whether the file was there or not. For starters, when the file is there, it is reporting as not being there and then the script bombs out without ever getting to the second hostname that has been read into a dictionary object from a file.
The code is as below:
Code:
For Each computer In oDictionary
compHost=oDictionary.item(computer)
WScript.Echo "Attempting to move log file from " & compHost
Call fileThere (compHost)
If fileThere=False Then
WScript.Echo "Despite 5 attempts, the file cannot be found"
Else
copyFile
End If
Next
function fileThere(compHost)
sourceFile="\\"&compHost&"\c$\"&UCase(compHost)&".txt"
WScript.Echo sourceFile
For i = 1 To 2
WScript.Echo "attempt " & i & " of 2"
Err.Clear()
If Not moveObjFSO.FileExists(sourceFile) Then
WScript.Sleep (3000)
End If
Next
fileThere=False
End Function
Sub copyFile (compHost)
WScript.Echo "Found"
objNetWork.MapNetWorkDrive "w:",path
If Err.Number=0 Then
moveObjFSO.Movefile sourceFile, logFileDest
Err.Clear
Else
'the machine may be in a workgroup so try the local admin account
objNetWork.MapNetWorkDrive "w:", path,,Tuser,TpassWord
If Err.Number<>0 Then
WScript.Echo compHost & " - cannot be connected to. Try manually"
Err.Clear
End If
End If
objNetWork.RemoveNetWorkDrive "w:"
End Sub
Any help would be great to get this working. Cheers.