Results 1 to 6 of 6

Thread: Count files in dir

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Swe
    Posts
    14

    Question

    Is there any function to count the number of files in a folder except the findfirst, findnext api´s?
    Jesse

  2. #2
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    Use Dir

    Code:
        a = Dir(path)
        Do While Len(a)
          FileNo = FileNo + 1
          a=Dir
        Loop

  3. #3
    Guest
    that bit of code will include other folders as files, so you will get a aflse result in some cases.

    Use the FSO to get more reliable results.

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

    <?>

    [code]
    'count files in a directory using FileSystemObject

    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FSO = FSO.GetFolder("C:\my documents")
    MsgBox FSO.Files.Count

    '
    '<<<<<<<<<<<<<<<<<<<?>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    'count files in a directory using dir

    Dim iFiles As Integer
    Dim sDir As String
    sDir = Dir("C:\My Documents\*.*", vbNormal + vbHidden + vbArchive + vbReadOnly + vbSystem)

    While sDir <> ""
    iFiles = iFiles + 1
    sDir = Dir
    Wend
    MsgBox iFiles
    [code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    The function i described does not include Directories.
    It returns the number of files.
    Check it out for yourself.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    Swe
    Posts
    14

    Smile Thnx!

    I´m going to create a component that optimizes the upload of files to a database (file stored in filesystem, path saved in db). It´s says that in order to speed things up you should store 500 files at the most in the same folder. So I don´t have to count all the files in subfolders.
    Jesse

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