Quality Testing

Quality is delighting customers

How to find the no.of files in a folder using QTP? Can any one help me the script.


Views: 4649

Reply to This

Replies to This Discussion

Hi malini..what exactly you want to accomplish counting files or retrieving files..if it's counting then:

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(PathofFolder)
Set oFiles = oFolder.Files
NumberOfFiles = oFiles.Count

msgbox "Total files:"&NumberOfFiles

Hi Bibek,

When I run this code I getting 1 count more.

In folder there are 10 files and I am getting ans as 11 could you please explain
Hi balur..it's working fine at my side:Eg. create a folder named "1" and add 3 text files under that folder. Run the script;the result must be 3.

Could u plz try once again..

If not; keep only one file under the folder;then check the result(Another test condition :) )

Index starts with 0;if this is the case you can use NumberOfFiles = oFiles.Count-1
(and it should not show 0 either; when there is 1 file... :) )
Thank You
There may be any hidden file in your folder.
Hi bibek,
This is basically a VBS solution i think the question is using QTP!!!
forget FSO is there a built in object in QTP to get on to FSO?
Sorry to say no..Abhijit there is no way to manipulate File system directly through QTP without creating an Instance with FSO.(same script is used in QTP too.)
This code is good and Bibek is right.

This can be simplified:

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("c:\")
msgbox "Total files:"&oFolder.Files.Count


TTWT Magazine





© 2021   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service