Results 1 to 3 of 3

Thread: Counting number of files in a folder

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2005
    Posts
    150

    Counting number of files in a folder

    How do I count the number of files in 3 folders ?

    Thank you

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Counting number of files in a folder

    If you use a FileListBox, its easy:
    VB Code:
    1. File1.Path = "C:\"
    2.     MsgBox File1.ListCount
    You also can specify extensions with:
    VB Code:
    1. File1.Pattern = "*.TXT"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Counting number of files in a folder

    If you elect to use code, the FSO requires the least amount.
    VB Code:
    1. 'Set A Reference To FileSystemObject
    2.  
    3. Private Function FileCount(ByVal FolderName As String) As Long
    4. Dim objFS As New Scripting.FileSystemObject
    5. Dim objFolder As Scripting.Folder
    6.  
    7. If objFS.FolderExists(FolderName) Then
    8.     Set objFolder = objFS.GetFolder(FolderName)
    9.     'if this lines returns more than 0, the folder has files
    10.     FileCount = objFolder.Files.Count
    11. End If
    12.  
    13. Set objFolder = Nothing
    14. Set objFS = Nothing
    15.  
    16. End Function
    17.  
    18. Private Sub cmdCheckForFiles_Click()
    19. MsgBox FileCount("C:\windows\system")
    20. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width