Any assistance appreciated.
I have a script i cobbled together.
I want the script to search through text files in a specified folder, it must search for a specific string in multiple text files.
If this string is found it must then copy files from one folder to another on the pc it is running.
The script runs without any errors, but the file copy does not execute.
I`ve created a text file that contains the string specified, but still no folder copy
Script :
Dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell 'instance of the wshSHell object
set objShell = CreateObject("WScript.Shell")
set oShellEnv = objShell.Environment("Process")
computerName = oShellEnv("ComputerName")
WScript.Echo computerName
strSearchFor = computerName
Set oFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Test"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
strFile = "C:\Test\" & objFile.Name
set objFile = objFSO.getFile(strFile)
If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
objFSO.CopyFolder "C:\test\ssavers\ssavers1" , "C:\screensavers\"
Else
WScript.Sleep (100)
END If
Next
I have a script i cobbled together.
I want the script to search through text files in a specified folder, it must search for a specific string in multiple text files.
If this string is found it must then copy files from one folder to another on the pc it is running.
The script runs without any errors, but the file copy does not execute.
I`ve created a text file that contains the string specified, but still no folder copy
Script :
Dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell 'instance of the wshSHell object
set objShell = CreateObject("WScript.Shell")
set oShellEnv = objShell.Environment("Process")
computerName = oShellEnv("ComputerName")
WScript.Echo computerName
strSearchFor = computerName
Set oFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Test"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
strFile = "C:\Test\" & objFile.Name
set objFile = objFSO.getFile(strFile)
If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
objFSO.CopyFolder "C:\test\ssavers\ssavers1" , "C:\screensavers\"
Else
WScript.Sleep (100)
END If
Next