How do I count the number of files in 3 folders ?
Thank you
Printable View
How do I count the number of files in 3 folders ?
Thank you
If you use a FileListBox, its easy:
You also can specify extensions with:VB Code:
File1.Path = "C:\" MsgBox File1.ListCount
VB Code:
File1.Pattern = "*.TXT"
If you elect to use code, the FSO requires the least amount.VB Code:
'Set A Reference To FileSystemObject Private Function FileCount(ByVal FolderName As String) As Long Dim objFS As New Scripting.FileSystemObject Dim objFolder As Scripting.Folder If objFS.FolderExists(FolderName) Then Set objFolder = objFS.GetFolder(FolderName) 'if this lines returns more than 0, the folder has files FileCount = objFolder.Files.Count End If Set objFolder = Nothing Set objFS = Nothing End Function Private Sub cmdCheckForFiles_Click() MsgBox FileCount("C:\windows\system") End Sub