Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Count the number of files inside a folder

    Hi, i am Kobs

    Please could you help me? i am new in programming and i want to know what's wrong with these codes? I want to count the number of files inside a folder, like how many *.dat file type inside the given path folder

    dim filepath As String = "C:\Gasresult"
    Dim dirInfo As New System.IO.DirectoryInfo(filepath)
    Dim intCount As Integer = Nothing
    Dim str As Integer = Nothing
    'Dim int1 As Integer = Nothing

    For Each files In dirInfo.GetFiles
    If dirInfo.Extension(files.FullName) = "dat" Then
    intCount = Convert.ToInt32(dirInfo)
    intCount = intCount + 1
    End If
    Next files
    MsgBox(intCount)

    everytime i execute the code, it always give me the error message >> conversion from string ..... to integer type is not valid or invalid

    Please help! very much appreciated! thanks!

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,895
    Thanks
    0
    Thanked 85 Times in 81 Posts
    That is VB.Net and not VBA but I think you just need to remove the
    Code:
    intCount = Convert.ToInt32(dirInfo)
    line
    Regards,
    Rory
    Microsoft MVP - Excel.

  4. #3
    Star Lounger
    Join Date
    Oct 2002
    Location
    Blue Mountains, New South Wales, Australia
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See this post, it lists two ways to do this in VBA.

Tags for this Thread

Posting Permissions

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