Hi,
I have this small VB script I found while googling that replaces commas from a text file. The problem is that I automated the whole process in a batch file and when the text has no commas, the VB script stops with a pop-up message saying that nothing was found, and it wont carry on until I press OK.
Could you help me modify it so that in case if founds nothing, it just quits and lets the batch file carry on forward?
Thanks for yor help,
Ben
I have this small VB script I found while googling that replaces commas from a text file. The problem is that I automated the whole process in a batch file and when the text has no commas, the VB script stops with a pop-up message saying that nothing was found, and it wont carry on until I press OK.
Could you help me modify it so that in case if founds nothing, it just quits and lets the batch file carry on forward?
Thanks for yor help,
Ben
Code:
Dim FileName, Find, ReplaceWith, FileContents, dFileContents
Find = WScript.Arguments(0)
ReplaceWith = WScript.Arguments(1)
FileName = WScript.Arguments(2)
FileContents = GetFile(FileName)
dFileContents = replace(FileContents, Find, ReplaceWith, 1, -1, 1)
if dFileContents <> FileContents Then
WriteFile FileName, dFileContents
Else
Wscript.Echo "Searched string Not In the source file"
End If
function GetFile(FileName)
If FileName<>"" Then
Dim FS, FileStream
Set FS = CreateObject("Scripting.FileSystemObject")
on error resume Next
Set FileStream = FS.OpenTextFile(FileName)
GetFile = FileStream.ReadAll
End If
End Function
function WriteFile(FileName, Contents)
Dim OutStream, FS
on error resume Next
Set FS = CreateObject("Scripting.FileSystemObject")
Set OutStream = FS.OpenTextFile(FileName, 2, True)
OutStream.Write Contents
End Function