Click here to Skip to main content
15,851,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

VB
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:
VB
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading)

-------------------------------------------------------
I Fixed this by opening the file in the correct encoding format
Posted
Updated 2-Dec-10 23:17pm
v5
Comments
Dalek Dave 3-Dec-10 4:17am    
Edited for Grammar.

1 solution

Your first steps should be:

Confirm the text.txt file exists.
Confirm you can read and write to the file in Notebook => If not you might have user permissions problems.

To give more help we'll need to which line is causing the error.

When you have more info, edit your question, please don't add an extra answer.
 
Share this answer
 
Comments
Dalek Dave 3-Dec-10 4:17am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900