09-17-2000, 02:34 PM
1. How can I count the number of files in a directory?
2. How can I take up each subdirectory of a directory (without knowing how many subdirectories there are & what's there name) for processing(say to print report about the directory contents), so that all the subdirectories are covered?
09-17-2000, 03:19 PM
There are a couple of ways to do this.
One way is to use the Dir$ command to list files and directories.
Another way is to use the filelist and directorylist controls.
Here's an example of a program that searches for mp3s using the Dir$ command
Private Sub Command1_Click()
Sub GetFilesFromDir(ByVal pth$)
Dim dirarray() As String
Dim n%, i%
s$ = Dir$(pth$ & "*.mp3")
Text1 = Text1 & vbCrLf & pth$ & s$
s$ = Dir$
s$ = Dir$(pth$ & "*.", vbDirectory)
n% = 0
If (s$ <> ".") And (s$ <> "..") Then
If Right$(s$, 1) <> """ Then s$ = s$ & """
ReDim Preserve dirarray(n%) As String
Debug.Print pth$ & s$
dirarray(n%) = pth$ & s$
n% = n% + 1
s$ = Dir$
For i% = 0 To n% - 1
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder