Hello... looking to count the numder of TIF files in a folder (thousands of folders really) without going by one file by one file within each folder. I saw some promising code but I get #VALUE in Excel or some kind of error each time. Suggestions?
Here's code I have to count ALL files in a folder (works just fine)... other code I've seen wants to use CMD prompt and/or namespace functions -- stuff I'm not super comfy with. Thanks!
Here's code I have to count ALL files in a folder (works just fine)... other code I've seen wants to use CMD prompt and/or namespace functions -- stuff I'm not super comfy with. Thanks!
Code:
Function fnCountFilesInFolder(pPath As String) As Long
On Error Resume Next
Dim fso As Object
Dim objFiles As Object
Dim obj As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFiles = fso.GetFolder(pPath).Files
If Err = 76 Then
Err = 0
fnCountFilesInFolder = -1 'record -1 files if the folder doesn't exist
Else
fnCountFilesInFolder = objFiles.Count
End If
Set objFiles = Nothing
Set fso = Nothing
Set obj = Nothing
End Function