Hi Guys,
I'm trying to write a very simple find and replace function in vbs.
Each time I run the script I get an access denied/ disk not ready error. (#71)
Anything I'm doing wrong?
Dim objFSO, objFile, strText, strNewText
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Jim", "James")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
--------------------------------------------------------
The File Exists, and the user can access it. I can edit it just fine in notepad.
The Error First appears here:
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)
-------------------------------------------------------
I Fixed this by opening the file in the correct encoding format