How would I get the number of files in a directory?
Like, I have 29 .htm files and 15 .txt files in a directory, I want to return the number of .htm files in a directory
Can anyone help me?
Printable View
How would I get the number of files in a directory?
Like, I have 29 .htm files and 15 .txt files in a directory, I want to return the number of .htm files in a directory
Can anyone help me?
Hi vaer,
Put a FileListBox control with the name of File1 on your form and to check, just execute the script below.
With Me.File1
.Path = "c:\windows\system\"
.Pattern = "*.htm"
MsgBox (.ListCount)
End With
Does it help ?
Regards
Thats the closest ive gotten so far, to what I need to do, Thanks a lot :)
I would like to be able to do it without a filelistbox though.... if thats possible...
Use the Dir Function and Count the Files Returned, eg.
------------------Code:Private Sub Command1_Click()
MsgBox NumFiles("C:\*.txt")
End Sub
Private Function NumFiles(ByVal sFileType As String) As Integer
Dim iCount As Integer
Dim sDir As String
sDir = Dir(sFileType, vbHidden + vbReadOnly + vbSystem + vbNormal)
While Len(sDir)
iCount = iCount + 1
sDir = Dir
Wend
NumFiles = iCount
End Function
Aaron Young
Analyst Programmer
[email protected]
[email protected]