Results 1 to 5 of 5

Thread: Retrieve the number of file of a particular extention...

  1. #1

    Thread Starter
    Addicted Member morphman2000's Avatar
    Join Date
    Oct 2000
    Location
    Europe, The Netherlands
    Posts
    254
    I want to retrieve the number of files with the extention ".txt" in a folder.

    Can somebody help me on this?

    Tnx.

    Dennie

  2. #2
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64
    Add a FileListBox to your form, set the path (file1.path) to be the folder you are looking at. Set the pattern (file1.pattern) to *.txt, then just do file1.listcount to return the number of txt files.

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Thumbs up

    Try this ...

    Code:
    Private Function GetNumberOfFiles(ByVal FolderName As String, _
                                      ByVal Extension As String) As Long
    
    Dim strFile As String
    Dim lngCount As Long
    
      lngCount = 0
      
      strFile = Dir(FolderName, vbNormal Or vbReadOnly Or vbHidden Or vbSystem)
      
      Do Until strFile = ""
      
        If Right$(strFile, 3) = Extension Then lngCount = lngCount + 1
        strFile = Dir
      
      Loop
    
      GetNumberOfFiles = lngCount
    
    End Function
    Call with ...

    Code:
      lngResult = GetNumberOfFiles("c:\SomeFolder\", "txt")
      MsgBox lngResult
    Hope this helps.
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  4. #4
    Member
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    54

    Talking Good code but very slow

    You should use the FindFiles API instead. This ones much faster but depending on the search area size, may take some time to.

    The code is long for it but is availabel on good VB-Code sites. Try:

    http://www.planet-source-code.com/xq...s/ShowCode.htm
    A mind is like a parachute, it has to open to let it work
    www.2beesoft.com for Icon Manager with over 20.000 free icons
    VB6 Ent. SP4, ASP, W2000/W98

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'just a plain and simple count (No Extras)

    Code:
    Private Sub Form_Load()
        'access all files within a folder
        
        Dim stFile As String
        Dim stDir As String
        Dim i As Integer
        
        stDir = "C:\My Documents\"     'the folder to search
        stFile = Dir$(stDir & "*.txt") 'type of files to select
        
        Do While stFile <> ""
          i = i + 1
          stFile = Dir
        Loop
    'do what you want to with the information supplied
        MsgBox "There are " & i & " files in " & _
                   stDir & " of txt type."
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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