Working with Files and Folders in UFT

It has been a while that we tend to post something relevant to operating with files and folders. Fortuitously we stumbled on a task of looking out a specific kind of files in our system drives.

How to search files on system using UFT


So we  leveraged that opportunity to share the simplified ideation for the same. As we all recognize that files are crucial part of our automation system, therefore we should always have some practical exposure to that.

We have segregated our approach to smaller requirements to have a clarity of the subject.

Please feel free to share your experience and knowledge on the same.


Requirement1:-


How to count number of Files inside a Folder

'Function Call
fn_FilesInFolder "C:UsersufthelpDocumentsPersonal"

Approach 1:-
'*******************************************Sub*******************************
'Function Name:- fn_FilesInFolder
'Function Description:- Function finds number of files inside a Given folder
'Input Parameters:- Folder Path
'Output Parameters:- None
'*****************************************************************************
Public Function fn_FilesInFolder(sPath)
Dim iFiles:iFiles = 0
'Creating a object to work with Files
Set objFSO = Createobject("Scripting.FileSystemObject")
'Creating a object to work with folders inside a given Folder Path
Set objFolders = objFSO.GetFolder(sPath)
'Creating a object to work with Files
Set objFiles = objFolders.Files
'Taking count of files Inside a particular folder path
For Each sFiles in objFiles
iFiles = iFiles +1
Next
msgbox "Folder = '"& sPath&"' contains '"& iFiles &"' number of Files"
End Function
Approach 2:-
'*******************************************Sub*******************************
'Function Name:- fn_FilesInFolder
'Function Description:- Function finds number of files inside a Given folder
'Input Parameters:- Folder Path
'Output Parameters:- None
'*****************************************************************************
Public Function fn_FilesInFolder(sPath)
Dim iFiles:iFiles = 0
'Creating a object to work with Files
Set objFSO = Createobject("Scripting.FileSystemObject")
'Creating a object to work with folders inside a given Folder Path
Set objFolders = objFSO.GetFolder(sPath)
'Creating a object to work with Files
Set objFiles = objFolders.Files
'Taking count of files Inside a particular folder path
iFiles = objFiles.Count
msgbox "Folder = '"& sPath&"' contains '"& iFiles &"' number of Files"
End Function

Requirment2:-Counting file types inside a Folder

Image courtesy of imagerymajestic / FreeDigitalPhotos.net