Showing posts with label Scripting.FileSystemObject. Show all posts
Showing posts with label Scripting.FileSystemObject. Show all posts

Sunday, 27 April 2014

QTP - UFT - How to open a text file using VBScript or How to open a flat file using VBScript





Open text file can be opened using "Scripting.FileSystemObject"

Syntax
filename = "c:\sample.txt"
strmode = 2
Set o1 = Createobject("Scripting.Filesystemobject")
If o1.FileExists(filename) = true Then
    set r1 = o1.OpenTextFile filename,strmode
 else
    ExitTest
End If
Msgbox r1.readall()

strMode represents the File Read mode and Any Text file can be opened in the following modes

ForReading  1  Open a file for reading only. You can't write to this file.
ForWriting 2 Open a file for writing.
ForAppending 8 Open a file and write to the end of the file.


QTP - UFT - How to create a text file using VBScript


 
We can use "Scripting.FileSystemObject"

strfilepath = "C:\Sample.txt"
Set obj = Createobject("Scripting.FileSystemObject")
If obj.FileExists(strfilepath)  = false Then
 obj.CreateTextFile strfilepath,true
End If
Set obj = nothing


Note:- To run the script copy and paste the script in Notepad and save it with extension ".vbs". Example "CreateFolder.vbs". Double click the file to run the script.

Or

Copy and paste the script in UFT / QTP and press F5 ( i.e. Run Button)
 
Happy Reading,
Sreenu Babu




 




 















QTP - UFT - How to create a folder using VBScript

We can use "Scripting.FileSystemObject".

Syntax
strFolderpath = "C:\SampleFolder"
Set obj = Createobject("Scripting.FileSystemObject")
If obj.FolderExists(strFolderpath) = false Then
 obj.CreateFolder strFolderpath
End If
Set obj = nothing


Note:- To run the script copy and paste the script in Notepad and save it with extension ".vbs". Example "CreateFolder.vbs". Double click the file to run the script.
Or
Copy and paste the script in UFT / QTP and press F5 ( i.e. Run Button)