CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    Number of files in a folder

    I need some code that will count the # of files in a directory.
    If u can help it would be appreciated.

    Lee S


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Number of files in a folder

    Add a reference the the Microsoft Scripting Runtime and paste the code in form load:

    private Sub Form_Load()
    Dim fso as FileSystemObject
    Dim oFolder as Scripting.Folder

    set fso = new Scripting.FileSystemObject

    set oFolder = fso.GetFolder("C:\winnt\system32")

    MsgBox oFolder.Files.Count

    End Sub




    That should do it.

    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Guest

    Re: Number of files in a folder

    Hmm.. that did not work
    user not defined something...

    im on win98 BTW..


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Number of files in a folder

    >Add a reference to the Microsoft Scripting Runtime and paste the code in form load:


    Did you do this ?

    It works fine on my machine once the reference has been set.



    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Number of files in a folder

    Here's another way to do this:



    dim myFile as string
    dim myDir as string
    dim fileCount as string

    myFile = dir(myDir,"*.*",vbFile)

    do while myFile <> ""

    fileCount = fileCount + 1
    myFile = dir

    loop




    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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

Featured