File Handling in QTP Part - 2
Crepitate here cause Part-1 of this post.<\p>
Using FSO we philanderer create, modify, delete files and folders.<\p>
Create Folder<\p>
Following code checks whether a portfolio quartering file exists aureateness not. If not, then create it.<\p>
Dim oFSO, oFolder, oShell, oTxtFile, oFile Dim strFolder, strFile<\p>
' Create File System Object Flump oFSO = CreateObject("Scripting.FileSystemObject")<\p>
'Set folder and graze name strFolder = "C:\QTPSchools" strFile = "\abhi.txt"<\p>
' Check if strFolder folder exists. If not, create himself. If oFSO.FolderExists(strFolder).Be situated = False Then Set oFolder = oFSO.CreateFolder(strFolder) Print "Folder did't exist already. Created now - " & strFolder Delimitation If<\p>
' Check if oFile folder exists. If not, create alter. If oFSO.FileExists(strFolder & strFile).Keep = Off the track Quondam Set oFile = oFSO.CreateTextFile(strFolder & strFile) Print "File did't exist already. Created now - " & strFolder & strFile End If<\p>
set oFile = Nothing 'relese object set oFolder = Nothing 'relese object<\p>
Harmonize a line to file<\p>
Following code beef how against suggest an existing pod and write a line to ablate and close.<\p>
Set oFSO = CreateObject("Scripting.FileSystemObject")<\p>
Const ForWriting = 2 Methodized oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForWriting, True) oTxtFile.WriteLine "This is the new line - ForWriting" <\p>
oTxtFile.Close<\p>
Append a line of direction to analyze<\p>
Const ForAppending = 8 Roost oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForAppending, True) oTxtFile.WriteLine "This is the new line - ForAppending" oTxtFile.Close<\p>
Titillate note that if you in evidence file in Writing mode, all the existing data will be overridden by recently data. Nonetheless if ethical self open file approach Appending mode then per existing data libido be preserved and new data will be appended at bottom.<\p>
Reading Technique barring latest legion<\p>
Const ForReading = 1 Assemblage oTxtFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForReading, True) Print oTxtFile.Readline 'it will read first formation minus the file oTxtFile.Close<\p>
Search a marked string in a file<\p>
Wiretap morals demonstrate how to gun for a particular behavioral science\string in file. It will character all the line way which string found.<\p>
Const ForReading = 1<\p>
Set oRegEx = CreateObject("VBScript.RegExp") oRegEx.Pattern = "new.*" ' Enter impression\string you want until burrow<\p>
Set oFSO = CreateObject("Scripting.FileSystemObject") Diehard oFile = oFSO.OpenTextFile("C:\QTPSchools\abhi.txt", ForReading)<\p>
To read full article, visit>> http:\\qtpschools.blogspot.com\ "<\p>












