File Handling in QTP
10 Jul 2008 - 05:48:10 pm
What is FSO?
       FSO stands for File System Object. This is used to support text file creation and manipulation through the TextStream object and is contained in the Scripting type library (Scrrun.dll)The FSO Object Model has a rich set of properties, methods and events to process folders and files.
How to create a file?
      We first create a FSO object using CreateObject and then create a text file using CreateTextFile.For Example: Suppose you want to create a file called "test.txt" located in C:
Dim fso, file, file_location
file_location = "C:file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set file = fso.CreateTextFile(file_location, True) // True--> file is to be overwritten if it already exists else false  We would use the same example for the rest of this post.
 
 How to open a file?
     Set file= fso.OpenTextFile("C:file_location", ForWriting, True)
 
//2nd argument can be ForReading, ForWriting, ForAppending
//3rd argument is "True"
if new file has to be created if the specified file doesn’t exist else false, blank signify false.

How to read content from a file?
   Use ReadLine() method
For example:
Set file= fso.OpenTextFile("C:file_location", ForReading, True)
//2nd argument should always be "ForReading" in order to read contents from a file
Do while file.AtEndofStream <> True     
data = file.ReadLine()
    
  msgbox data
Loop

How to write content to a file?
     You can use  Write() or WriteLine() Methods to write text into a file. The difference between the Write() and WriteLine() Method is that the latter automatically inserts a new line character while the former doesn’t insert a new line character.
  For example:
  Set file= fso.OpenTextFile("C:file_location", ForWriting, True) //
 2nd argument should always be "ForWriting" in order to write contents to a file
file.Write("This is a place to get all your qtp") file.Write("questions and answers solved.")//Output will be: This is a place to get all your qtp questions and answers solved. whilefile.WriteLine("This is a place to get all your qtp") file.Write("questions and answers solved.")//Output will be: This is a place to get all your qtpquestions and answers solved.

How to delete content?
     Use DeleteFile() method to delete a file from a particular locationFoe Example:
   file_location = "C:file_location"
Set fso = CreateObject(“Scripting.FileSystemObject”)
fso.DeleteFile(file_location
Admin · 1687 views · 63 comments
Categories: File System Objects

Permanent link to full entry

http://automation-qtp.discussionsblog.com/QTP-b1/File-Handling-in-QTP-b1-p8.htm

Comments

No comments are allowed in this blog


Leave a comment

No comments are allowed in this blog

Last Comment

Yes, Even I agree. Some of ...

2009-12-22 @ 05:59:03 pm
by siva


I agree, some of the answers ...

2009-11-09 @ 03:59:29 pm
by ashwani


Can anyone tell me how to ...

2009-03-01 @ 12:38:47 pm
by harshada


Hi Can anyone help me out ...

2008-11-20 @ 05:01:49 pm
by Ramesh


some of your answers are wrong....

2008-09-15 @ 03:28:25 pm
by avnish


please post HP0-M80 & HP0-M81 Sample ...

2008-08-22 @ 08:46:36 pm
by Test


Hi dhruv, ...

2008-07-28 @ 08:35:15 am
by suri


Hi all,

This blog is ...

2008-07-28 @ 06:47:17 am
by dhruv


hi experts, this is gud site.. from ...

2008-07-22 @ 11:19:25 pm
by rameshtt


Hi , Here I'm giving a ...

2008-07-17 @ 03:59:04 pm
by lavanya


You can do that by using ...

2008-07-17 @ 09:01:26 am
by suri


How to Highlight the textbox data 'To ...

2008-07-17 @ 08:58:30 am
by suri


Please provide answers to these questions

2008-07-16 @ 03:53:48 pm
by Sreekanth


Hi , ...

2008-07-16 @ 12:50:21 pm
by Admin


We can do the same in ...

2008-07-16 @ 12:34:07 pm
by Admin


Who's Online?

Member: 0
Visitor: 1

Announce

Tags

No tags in this Blog

rss Syndication

Archives