lundi 2 mars 2015

vb script if statement

i`m sorry my english language is too bad

i want to edit a file with VB if the word that must to be in file isnt exist. when execute this file, i want if condition was true do nothing but all file content was erase. please help me.



Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\path\to\file.html", ForReading)

strText = objFile.ReadAll
objFile.Close
strSearchFor = "this word must to exist"

If InStr(1, strText, strSearchFor) > 0 then
'do nothing
else
strNewText = Replace(strText,"this word must to delete","this word must to exist" )
End If
Set objFile = objFSO.OpenTextFile("C:\path\to\file.html", ForWriting)
objFile.WriteLine strNewText
objFile.Close

Aucun commentaire:

Enregistrer un commentaire