vbs script to search a string in a textfile and add string if not found
Hi
I'm searching a vbs script which searches a string in a defined textfile.
If the string is not found it should be added in the file.
Can somebody help me?
Thank you.
I'm searching a vbs script which searches a string in a defined textfile.
If the string is not found it should be added in the file.
Can somebody help me?
Thank you.
2 Comments
[ + ] Show comments
Answers (7)
Answer Summary:
Please log in to answer
Posted by:
pjgeutjens
15 years ago
This should work:
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objShell = Wscript.CreateObject("Wscript.Shell")
Const FORREADING = 1
Const FORWRITING = 2
Const FORAPPENDING = 8
Dim sToSearch: sToSearch = "What you're Looking for"
Dim sFileName: sFileName = "C:\Temp.txt"
Dim sContent, Found
If Not objFSO.FileExists(sFileName) Then
MsgBox "File Not Found"
WScript.Quit 0
End If
Set TxtFile = objFSO.OpenTextFile(sFileName,FORREADING)
sContent = TxtFile.ReadAll
If InStr(sContent,sToSearch) Then Found = True End If
Set TxtFile = Nothing
If Not Found Then
Set TxtFile = objFSO.OpenTextFile(sFileName,FORAPPENDING)
TxtFile.WriteLine sToSearch
End If
Posted by:
pjgeutjens
15 years ago
Posted by:
TimoP
9 years ago
Posted by:
EdT
9 years ago
Posted by:
AcIvI
9 years ago
Posted by:
Sanfoor
9 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.
Please help me i wand to do this as soon as possible.
Thanks in advance. - ChinnuM 10 years ago