List all QTP tests from a given folder

The following custom functions are recursive and use the system FileSystemObjectfunctionality to scan the folders and subfolders of a given path, then based on the files and folder names found, output the folder names that are QTP tests.

Option Explicit

Dim objFso
Dim strRootFolder
Dim isTest

Sub GetSubFolders(sFolder)
On Error Resume Next
Dim cSf
Dim oFolder
Dim oSf
Set oFolder = objFso.GetFolder(sFolder)
Set cSf = oFolder.SubFolders
If cSf.Count > 0 Then
For Each oSf In cSf
If oSf.Name = "Action0" Then
Call getFiles(oSf.Path)
Exit For
End If
Call getSubFolders(oSf.Path)
Next
Else
For Each oSf In cSf
Call getFiles(oSf.Path)
Next
End If
Set oFolder = Nothing
Set cSf = Nothing
End Sub

Sub GetFiles(sFolder)
On Error Resume Next
Dim cF
Dim oFile
Dim oFolder
Set oFolder = objFso.GetFolder(sFolder)
Set cf = oFolder.Files
For Each oFile In cF
If oFile.ShortName = "ObjectRepository.bdb" Or oFile.ShortName = "Resource.mtr" Or oFile.ShortName = "Script.mts" Then
isTest= True
Exit For
Else
isTest = False
End If
DoEvents
Next
If isTest Then
Print oFolder.ParentFolder.Name &" on "& oFolder.ParentFolder.Path & " is a test"
End If
Set oFolder = Nothing
Set cF = Nothing

End Sub

Usage Example:

Set objFso = CreateObject("Scripting.FileSystemObject") ‘Get instance of FileSystemObject
strRootFolder = "C:\Cases" ‘Set the root folder to begin the scan from
GetFiles strRootFolder
GetSubFolders strRootFolder

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s