Header Ads

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!!

Powered by Blogger.