Posts

Showing posts with the label FileSystemObject

How to Use the VBScript RegExp Object

  Hi All, I faced a situation where I had to update the field’s value from another file. I can not use the string replace method because It will replace the all the matches value, While I want to replace the first match with the first value of another file.  Here I am trying to explain First File Contents: This blog refers to QTP. I want to get first line value "="   from another file. Here I am using Rexexp with global property value false Now I want to get Second line value "="   from another file. Global property false will serach only first match If regexp global property true then it search all the matches Now I want to get Third line value "="   from another file. Second File Contents: Rajiv Kumar Nandvani I want output like this: This blog refers to QTP. I want to get first line value " Rajiv "  from another file. Here I am using Rexexp with global property value false Now I wan...

Adding Data to the File Working with files(FileSystemObject) / QTP

Adding Data to the File Once the text file is created, add data to the file using the following three steps: Open the text file. Write the data. Close the file. To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object. To write data to the open text file, use the Write , WriteLine , or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table Task Method Write data to an open text file without a trailing newline character.       Write Write data to an open text file with a trailing newline character. WriteLine Write one or more blank lines to an open text file. WriteBlankLines To close an open file, use the Close method of the TextStream object. Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the nex...

Creating Files Working with files(FileSystemObject) / QTP

Creating Files There are three ways to create an empty text file (sometimes referred to as a “text stream”). The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using the CreateTextFileMethod method. [VBScript] Dim fso, f1 Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile("c:\testfile.txt", True) [JScript] var fso, f1; fso = new ActiveXObject("Scripting.FileSystemObject"); f1 = fso.CreateTextFile("c:\\testfile.txt", tr The second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set. [VBScript Dim fso, ts Const ForWriting = 2 Set fso = CreateObject("Scripting. FileSystemObject") Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True) [JScript] var fso, ts; var ForWriting= 2; fso = new ActiveXObject("Scripting.FileSystemObject") ts = fso.OpenTe...