Code to Count the Number of Files in a Folder in QTP

This is the sample code to count the number of files in a folder
Now where to use this??
Well most of the time I used it report generation.
Say i want to store report in a particular folder script wise.In my early days of testing I had 22 scripts to run and I had to store 22 results files.
That time i used to count the number of files present in a folder and determine the the next name name and number .
Second use was during installation testing.I was testing a .exe file. The installation was done correctly but all the files ware not placed correctly under its specified folder.To test that condition I had used this simple code to determine if each folder has its original and specified number of files.

iFileCount = 0
Set objFileSysOb = CreateObject("Scripting.FileSystemObject")
Set colFolderName = objFileSysOb.GetFolder("C:\Automation") ' Folder Path
Set vFiles =colFolderName.Files
For each vFileItem in vFiles
msgbox vFileItem
iFileCount = iFileCount + 1
msgbox iFileCount

Hope this helps you. Let me know if this helps you to solve any problem!!
Code to Count the Number of Files in a Folder in QTP Code to Count the Number of Files in a Folder in QTP Reviewed by Animesh Chatterjee on February 15, 2009 Rating: 5

1 comment:

  1. One Question:

    When my manager takes the scripts, he wants to run them from his D drive. But I have written the scripts in such a way that it gets executed and stores the results in an Excel at C drive. To avoid this, I want to get the current folder path. How to do that?


Powered by Blogger.