Sunday 24 November 2013

Filesystemobject methods in QTP

Filesystemobject is used to access the computer's file system in QTP. You can read, edit, delete files using this object. You can also create/ delete folders using this object in QTP.

Most important methods of Filesystemobject

CopyFile Method ----------->copies file from one location to other with option to overwrite existing file
CopyFolder Method---------->copies folder and its contents from one location to other with option to overwrite existing folder
CreateFolder Method-------->creates a new folder. If the folder already exists, error occurs. So before creating a folder, check for its existance
CreateTextFile Method------>creates a new file and returns the textstream object with option to overwrite and format mode (Ascii or unicode)
DeleteFile Method---------->deletes the specified file. Error occurs if the given file does not exist
DeleteFolder Method-------->deletes the specified folder. Error occurs if the given folder does not exist
DriveExists Method--------->returns true if the given drive exists in the system else returns false
FileExists Method---------->returns true if the given file exists in the system else returns false
FolderExists Method-------->returns true if the given folder exists in the system else returns false
GetDrive Method------------>returns drive object for the given drive
GetFile Method------------->returns file object for the given file
GetFolder Method----------->returns folder object for the given folder
MoveFile Method------------>moves file from one location to another
MoveFolder Method---------->moves folder and it's contents from one location to another
OpenTextFile Method-------->opens the text file and returns the textstream object with option of iomode, create new file and format mode(ascii/unicode)

GetDriveName Method-------->gets the drive name for the given path
GetFileName Method--------->gets the file name (last component ) for the given path
GetExtensionName Method---->gets the extension for the given path like txt, mp3 etc
GetAbsolutePathName Method->gets the complete path for the given relative/absolute path
GetBaseName Method--------->gets the name of file (last component) excluding extension
GetParentFolderName Method->Gets the name of parent folder


Filesystemobject has only one property 
Drives Property------------>returns the collection of the drives objects in the system

Examples on filesystem object

   Set fso = CreateObject("Scripting.FileSystemObject")

   print fso.GetdriveName("c:\sagar\bl\metachara.txt")
   'output -  c:
   print fso.GetAbsolutePathName("c:\sagar\bl\metachara.txt")
   'output - C:\sagar\bl\metachara.txt
   print fso.GetExtensionName("c:\sagar\bl\metachara.txt")
   'output - txt
   print fso.GetBaseName("c:\sagar\bl\metachara.txt")
   'output - metachara
   print fso.GetFileName("c:\sagar\bl")
   'output - bl

You may also like below topics on file handling in QTP.

  1. Create a text file in QTP.
  2. Delete a folder in QTP
  3. Delete an Excel file in QTP
  4. Create a folder in QTP.
  5. Rename a file in QTP.
  6. Append contents to text file in QTP.
  7. Copy text file in QTP.
  8. Write data to text file in QTP.
  9. Check if file exists in QTP.
  10. Copy folder in QTP.
  11. Read a text file in QTP.
  12. Check if folder exists in QTP.
  13. Delete text file in QTP.

Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.