Count # of CERTAIN files in a folder but not one by one

Note: But you can also read the output from Dir directly as a string if you don't want to use a file.

Base on #5:
Code:
Dim StdOut As String
Dim Files() As String

With CreateObject("WScript.Shell")
   StdOut = .Exec("cmd.exe /c dir """ & StartDirectory & "\*." & FileExtension & """ /b /s").StdOut.ReadAll
End With
If Right(StdOut, Len(vbNewLine)) = vbNewLine Then
   StdOut = Left(StdOut, Len(StdOut) - Len(vbNewLine))
End If
Debug.Print ">" & StdOut & "<"

Files = Split(StdOut, vbNewLine)
Debug.Print UBound(Files) + 1
 
I'm going to throw an excel solution out there - I know this is in the modules & VBA Access category, but maybe excel can fit your requirements.

Steps:
1. Open new excel workbook
2. Click data tab
3. Click get data button -> from file -> from folder
4. Select starting folder location you want to begin the search at
5. Click transform data. This will open the power query editor
6. Filter the 'Extension' column to .tif

Now you could click close & load and send the list of all .tif files to a new excel sheet - or if you only want the count results.

7. click the transform tab, and then count rows button
8. click 'to table'

This file is updatable with the refresh button too, so if you remove or add .tif files, you can easily get the new count.
You can also schedule a job with task manager to refresh on open if you need it updated daily or at a certain time.
 

Users who are viewing this thread

Back
Top Bottom