Working with Files and Folders in UFT – User friendly Tech help

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.

n

nSo 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.
n
nWe have segregated our approach to smaller requirements to have a clarity of the subject.
n
nPlease feel free to share your experience and knowledge on the same.
n
n

n

Requirement1:-

n

How to count number of Files inside a Folder

n

'Function Call

n

fn_FilesInFolder "C:UsersufthelpDocumentsPersonal"

n

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

n

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

n

Requirment2:-Counting file types inside a Folder

n

Image courtesy of imagerymajestic / FreeDigitalPhotos.net

Was this article helpful?
YesNo

Similar Posts