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. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,939
    Thanks
    0
    Thanked 94 Times in 90 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.

  3. #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
  •