Text file handling in QTP

Text file handling in QTP

Const ReadTXT = 1
Const WriteTXT = 2

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘Suppose you have 100 TXT files needs to be read and updated – then load those files in input XLS file.
FilePath = Datatable(“FilePath”) & “.txt”

Set objFile = objFSO.OpenTextFile(FilePath, ReadTXT)

strText = objFile.ReadAll

objFile.Close

strNewText = Replace(strText, Datatable(“OldValue”), Datatable(“NewValue”))

Set objFile = objFSO.OpenTextFile(FilePath, WriteTXT)

objFile.WriteLine strNewText

objFile.Close