Counting File types inside a Folder structure. – User friendly Tech help

How to get count of particular file type inside a Folder.

n

'Function Call 
fn_FilesInFolder "C:UsersufthelpDocumentsPerso","pdf"
'*******************************************Sub*******************************
'Function Name:- fn_FilesInFolder
'Function Description:- Function finds number of particular files inside a Given folder
'Input Parameters:- Folder Path,File Type
'Output Parameters:- None
'*****************************************************************************
Public Function fn_FilesInFolder(sPath,sFileType)
Dim iFiles:iFiles = 0
Dim iCount:iCount = 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
'Getting the Extension of the file
sExtn = objFSO.GetExtensionName(sFiles.Name)
'Comparing the Extension
If Ucase(sExtn) = Ucase(Trim(sFileType)) Then
iCount = iCount + 1
End If
Next
msgbox "Folder = '"&sPath &"' contains '"& iCount &"' number of files with the extension of '"&sFileType&"'"
End Function

n

Image courtesy of hywards / FreeDigitalPhotos.net

Was this article helpful?
YesNo

Similar Posts