I have the following script. Want the number of folder, subfolders and files:
Sub CountFiles(ByVal path1 As String)
Dim fso As Object
Dim subfolder As Object
Dim file As Object
Dim folder As Object
Dim stetje As Long
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(path1)
For Each subfolder In folder.SubFolders
CountFiles (subfolder.path)
Next subfolder
For Each file In folder.Files
Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = file.path
Next file
Set fso = Nothing
Set folder = Nothing
Set subfolder = Nothing
Set file = Nothing
End Sub
Which you call as:
Sub someStuff()
Call CountFiles ("c:/temp/test/")
End Sub
This script writes into Excel cells paths to all the folders, subfolders and files
But what I really want is to count the TOTAL of all the the occurrences into a variable.
So instead of this:
For Each file In folder.Files
Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = file.path
Next file
I would like something like this:
For Each file In folder.Files
number = number + file.path.Count // of course this line is completely pseudo
Next file
So the wanted output is for example the number: 2345 and not 2345 rows with paths written out.
Any help / hints would be appreciated!