PDA

Click to See Complete Forum and Search --> : Counting files...


vaer
Nov 25th, 1999, 02:12 AM
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?

Keiko
Nov 25th, 1999, 07:45 AM
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

vaer
Nov 25th, 1999, 08:06 AM
Thats the closest ive gotten so far, to what I need to do, Thanks a lot :)

vaer
Nov 25th, 1999, 08:15 AM
I would like to be able to do it without a filelistbox though.... if thats possible...

Aaron Young
Nov 25th, 1999, 11:28 AM
Use the Dir Function and Count the Files Returned, eg.

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
aarony@redwingsoftware.com
adyoung@win.bright.net