Count the number of text files in directory sub folders (1 Viewer)

JohnLee

Registered User.
Local time
Today, 02:29
Joined
Mar 8, 2007
Messages
692
Good morning I'm somewhat struggle to create/find code that will count the number of text files in a directory with one level of folders please see below:

Directory path is : B:\

First and only level of sub folders:

there are 100 of these and they all end in ".fof"

These .fof folders will always contain .txt files.

I've tried using the following code, but it always returns No files found.

Code:
Dim lngFileCount As Long
Dim StrFileName As String
StrFileName = Dir$("B:\*.txt")
Do While Len(StrFileName) <> 0
    lngFileCount = lngFileCount + 1
    StrFileName = Dir$
Loop
Debug.Print " Total Files are : " & lngFileCount

and the following code:

Code:
Dim file As Variant
file = Dir("B:\")
Dim i As Integer
While (file <> "")
i = i + 1
Debug.Print file & " " & i
file = Dir
Wend
Debug.Print "Total file is: " & i

Any assistance would be most appreciated.

Regards

John
 

Users who are viewing this thread

Top Bottom