Total file count in folder and subfolders

  • This code works great for a target folder count. But some of my target folders now have hundreds of sub folders. How do I make it search a folder and subfolders and return a total file count? Need it to search all file types.


  • Re: Total file count in folder and subfolders


    Try this, fastest way is using command prompt.


    Code
    FolderPath = "C:\Share\2015\My_Project\HwySign"
    
    
    Dim fCount As Long
    
    
    fCount = UBound(Filter(Split(CreateObject("WScript.Shell").Exec("CMD /C DIR """ & FolderPath & "\*.*"" /S /B /A:-D").StdOut.ReadAll, vbCrLf), ".")) + 1
    
    
    MsgBox Format(fCount, "#,00") & " files were found."


    A black box will appear for a minute while it searches for files - this is normal.

  • Re: Total file count in folder and subfolders


    Yes it works pretty good, but I have no use for the msg box that pops up. I need the results to post into a specified cell.

  • Re: Total file count in folder and subfolders


    Got this to work searching only subfolders, It will be good enough.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!