Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Capture the number of files in a folder (2003 sp2)

    I am extracting data from a large number of files in a folder and placing it in a table in a database. The process begins by building a list of all the file names in the folder and placing them in a table and then looping through the table names to extract the data. HansV helped me with this last year.

    To verify that I have captured all the files in the folder I would like to compare the number of files in the folder with the number of files in my table. How can I get the number of files the folder contains. I know the status bar in windows explorer displays the number of objects but have no idea how to get this information.
    Thanks
    chuck

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capture the number of files in a folder (2003 sp2)

    For example like this:

    Sub GetFileCount()
    Const strFolder = "C:Access"
    Dim fso As Object
    Dim fld As Object
    Dim intCount As Integer
    On Error GoTo ErrHandler
    ' Create File System Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    ' Get folder
    Set fld = fso.GetFolder(strFolder)
    ' Get file count
    intCount = fld.Files.Count
    ' Do something
    MsgBox intCount & " files"
    ExitHandler:
    Set fld = Nothing
    Set fso = Nothing
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Capture the number of files in a folder (2003 sp2)

    Exactly what I need Hans, Thanks!
    Thanks
    chuck

Posting Permissions

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