count files

mastana
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?

BillSoo
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()
GetFilesFromDir "c:""
End Sub

Sub GetFilesFromDir(ByVal pth$)
Dim s$
Dim dirarray() As String
Dim n%, i%

s$ = Dir$(pth$ & "*.mp3")
While Len(s$)
Text1 = Text1 & vbCrLf & pth$ & s$
s$ = Dir$
Wend

s$ = Dir$(pth$ & "*.", vbDirectory)
n% = 0
While Len(s$)
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
End If
s$ = Dir$
Wend
For i% = 0 To n% - 1
GetFilesFromDir dirarray(i%)
Next i%
End Sub

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum