Micro Focus QTP (UFT) Forums
Copy text from file1, Replace text from file2 with text from file1 - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Copy text from file1, Replace text from file2 with text from file1 (/Thread-Copy-text-from-file1-Replace-text-from-file2-with-text-from-file1)



Copy text from file1, Replace text from file2 with text from file1 - bjotorres - 11-10-2008

I want to replace text from file2 with text copied from file1 using QTP. Can anyone help me find my way?


RE: Copy text from file1, Replace text from file2 with text from file1 - roxer - 12-04-2008

hi, bjotorres
Here simple code that I wrote.
Code:
'path to file from which text will be copied
fromPath = "c:\from.txt"
'path to file where text should be replaced
toPath = "c:\to.txt"
textThatShouldBeReplaced = "some text to search"

'create File System Object to perform manipulations with files
Set fso = CreateObject("Scripting.FileSystemObject")
'Open text file for reading, copy text from it and close it
Set from_file = fso.OpenTextFile(fromPath, 1)
copiedText = from_file.ReadAll
from_file.Close
'Open text file for writing, replace text in it and close it
Set to_file = fso.OpenTextFile(toPath, 1)
fileText = to_file.ReadAll
to_file.Close
fileText = Replace(fileText, textThatShouldBeReplaced, copiedText, 1, -1, 1)
Set to_file = fso.OpenTextFile(toPath, 2)
to_file.Write fileText
to_file.Close
Maybe it'll help you.