Results 1 to 5 of 5

Thread: Counting files...

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    6

    Post

    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?

  2. #2
    Addicted Member
    Join Date
    Sep 1999
    Posts
    229

    Post


    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    6

    Post

    Thats the closest ive gotten so far, to what I need to do, Thanks a lot

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    6

    Post

    I would like to be able to do it without a filelistbox though.... if thats possible...

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

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

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