0

This is my first day with VB scripting. I found following code to search and replace text in a text file but when I run that using the following command

cscript replace.vbs "test.txt" "Jim" "James"

I get an error saying

replace.vbs(6, 1) Microsoft VBScript runtime error: Object required: 'Scripting'

Here is the code

Const ForReading = 1    
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject(Scripting.FileSystemObject)
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText  'WriteLine adds extra CRLF
objFile.Close

1 Answer 1

2

Use

Set objFSO = CreateObject("Scripting.FileSystemObject")

(mark the quotes, CreateObject() needs a string)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.