Link to home
Start Free TrialLog in
Avatar of bt707
bt707Flag for United States of America

asked on

vbs add line if it does not exist

I have a ini file that I need to replace a few lines in, with the code below I can replace the two lines I need and that works fine.

The problem I have is that some of the files does not contain a line of DefaultMailto, how can I check to see if the file contains the line of DefaultMailto and if not then add DefaultMailto=0. Also the file sometimes does have a line of WarnDefaultMailto= so also have to keep this line from being found when looking for DefautlMailto=.

Thanks,










Const ForReadingPRF = 1
Const ForWritingPRF = 2
Set objFSOPRF = CreateObject("Scripting.FileSystemObject")
Set objFilePRF = objFSOPRF.OpenTextFile(EiniPath, ForReadingPRF)
newPOPaccount = "POPAccount=" & MigrateAlias & "@NO_PoP_Mail"
 
strTextPRF = objFilePRF.ReadAll
objFilePRF.Close
strNewTextPRF = Replace(strTextPRF, "DefaultMailto=1", "DefaultMailto=0")
strNewTextLOS = Replace(strNewTextPRF, "POPAccount=NO_PoP_Mail", newPOPaccount)
 
Set objFilePRF = objFSOPRF.OpenTextFile(EiniPath, ForWritingPRF)
objFilePRF.WriteLine strNewTextLOS
objFilePRF.Close

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bt707

ASKER

That help and I got it going now.

Thanks,