Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use USERPROFILE variable with OpenTextFile?

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
0
0
US
I have this part of a script I'm writing that I'd like use to find a bit of text in a results file and replace it with some other text. It is not working and I was hoping someone could tell me how to get it to work!

Thanks in advance!

Code:
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(%USERPROFILE% & "\Desktop\Systems.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Error:", "System is blah - no information will be retrieved!")

Set objFile = objFSO.OpenTextFile(%USERPROFILE% & "\Desktop\Systems.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close

[!]The AutoSavers![/!] [2thumbsup]
 
It is not working
What happens ? any error message ? computer crash ? unexpected behaviour ? ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the link!

Here is the working code:
Code:
Const ForReading = 1
Const ForWriting = 2

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strDesktop & "\Systems.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Error:", "System is blah - no information will be retrieved!")

Set objFile = objFSO.OpenTextFile(strDesktop & "\Systems.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close

[url=http://cbsarge.com][!]The AutoSavers![/!][/url] [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top