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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add line to txt.file

Status
Not open for further replies.

Tranbjerg

IS-IT--Management
Jul 31, 2003
8
DK
Hi all

I need to change a vbs script so it first search for a line and change it. But I also need to make a check to see if the line exist else it has to create it. In other words, the script has to check if the line names is in the file and change it and if the line doesn't exist it has to create it.

Here's the script that just changes the line
Set TF=FSO.OpenTextFile(notesini,1)
inp=TF.ReadAll
out=Replace(inp,"Names=Names.nsf","NAMES=C:\Documents and Settings\"+struser+"\Application Data\Notes\Names.nsf",1,-1,vbTextCompare)
TF.close
Set TF=FSO.CreateTextFile(notesini,True)
TF.Writeline out
TF.Close
 
Try something like this:
Code:
newtxt="NAMES=C:\Documents and Settings\" & struser & "\Application Data\Notes\Names.nsf"
Set TF=FSO.OpenTextFile(notesini,1)
inp=TF.ReadAll
out=Replace(inp,"Names=Names.nsf",newtxt,1,-1,vbTextCompare)
TF.close
Set TF=FSO.CreateTextFile(notesini,True)
TF.Writeline out
If out=inp Then TF.WriteLine newtxt
TF.Close

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top