Function GetFileCount(ByVal sFolderPath, ByVal sExt)
Dim iCount
Dim oFile, pFolder
Dim fso
On Error Resume Next
Set fso=CreateObject("Scripting.FileSystemObject")
set pFolder=fso.GetFolder(sFolderPath)
set oFile=pFolder.Files
For each sFile in oFile
If instr(1,lcase(sFile.Path),sExt,1)>0 Then 'It's a text comparison
iCount=iCount+1
End IF
Next
'Count all files in each subfolder – recursion point
For Each SubFld In pFolder.SubFolders
iCount = iCount + GetFilecount(SubFld.Path, sExt)
Next
GetFilecount=iCount 'Return the count to the calling statement
Set fso=Nothing
End Function
sPath="E:\Debajit Hazarika\EDI Files"
sCount=GetFileCount(sPath, ".mbi")
Msgbox "Total Count ="&sCount
No comments:
Post a Comment