Scorecard Handling in QTP Part - 2
Tinkle here for Part-1 of this post.<\p>
Using FSO we can create, modify, delete files and folders.<\p>
Create Folder<\p>
Following code checks whether a book table or file exists or not. If not, then rough out it.<\p>
Faint oFSO, oFolder, oShell, oTxtFile, oFile Dim strFolder, strFile<\p>
' Occasion File System Object Set oFSO = CreateObject("Scripting.FileSystemObject")<\p>
'set bookrack and stow down name strFolder = "C:\QTPSchools" strFile = "\abhi.txt"<\p>
' Check if strFolder folder exists. If not, create it. If oFSO.FolderExists(strFolder).Exist = False Then Set oFolder = oFSO.CreateFolder(strFolder) Print "Folder did't exist up to now. Created contemporaneousness - " & strFolder End If<\p>
' Check if oFile folder exists. If not, create it. If oFSO.FileExists(strFolder & strFile).Exist = Fraudulent Then Set oFile = oFSO.CreateTextFile(strFolder & strFile) Print "File did't exist heretofore. Created now - " & strFolder & strFile End If<\p>
set oFile = Nothing 'Relese object set oFolder = Nothing 'Relese object<\p>
Write a job lot to gall<\p>
Following encipher signify how to open an existing file and write a line to file and close.<\p>
Set oFSO = CreateObject("Scripting.FileSystemObject")<\p>
Const ForWriting = 2 Number oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForWriting, True) oTxtFile.WriteLine "This is the new line - ForWriting" <\p>
oTxtFile.Close<\p>
Append a line to file<\p>
Const ForAppending = 8 Sept oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForAppending, Suitable) oTxtFile.WriteLine "This is the new line - ForAppending" oTxtFile.Open<\p>
Suit note that if you to be had file a la mode Writing mode, all the existing data will have place overridden by new-fashioned data. Save if you open file in Appending mode then integral existing data will abide saved and new data will be found appended at watercraft.<\p>
Reading Data from contemporary file<\p>
Const ForReading = 1 Set oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForReading, True) Print oTxtFile.Readline 'it will read up ahead line from the emery paper oTxtFile.Close<\p>
Search a particular follow in a wreath<\p>
Following code demonstrate how over against search a particular constitution\string modernistic file. It will scrape all the line in which catena torrefy.<\p>
Const ForReading = 1<\p>
Set oRegEx = CreateObject("VBScript.RegExp") oRegEx.Pattern = "new.*" ' Enter pattern\faction you want to search<\p>
Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForReading)<\p>
To read full article, visit>> http:\\qtpschools.blogspot.com\ "<\p>













