• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Count files in folder

Status
Not open for further replies.

Abhijeet

Active Member
Hi

I want to count all excel, Word, Pdf, Tif, .msg in folder file extension wise i want count please tell me how to do this
Code:
Sub sample()

    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "C:\Users\swami\Desktop\Temp"

    path = FolderPath & "\*.xls"

    Filename = Dir(path)

    Do While Filename <> ""
      count = count + 1
        Filename = Dir()
    Loop

    Range("A2").Value = count
    'MsgBox count & " : files found in folder"
End Sub
 
Check this..

Code:
Sub sample1()

    Dim FolderPath As String, x As String, count As Integer, s As String
    FolderPath = "C:\Users\swami\Desktop\Temp"

    x = FolderPath & Dir(FolderPath & "\*.*")
   
    Do While x <> ""
    s = Mid(x, InStrRev(x, ".") + 1)
        Select Case WorksheetFunction.CountIf(Columns(1), s)
            Case 0
                count = Application.CountA(Columns(1)) + 1
                Cells(count, 1) = s
                Cells(count, 2) = 1
            Case Else
                count = WorksheetFunction.Match(s, Columns(1), 0)
                Cells(count, 2) = Cells(count, 2) + 1
        End Select
        x = Dir
    Loop
End Sub
 
Thanks Deepak its work fine

Can u pls tell me as file extension create folder & move those files in that folder how to do this
 
Yes Deepak i ask question count files but if those files can move to as per extension folder then that will help me Please tell me how to do this
 
Status
Not open for further replies.
Back
Top