Link to home
Start Free TrialLog in
Avatar of sanjshah12
sanjshah12Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Get number of Files in Directory and Sub Directories

Hi,

I am using the code below to obtain the number of files in a directory but would like to also check the number of files that might be present in any sub directories of the main folder, I need this to be efficient as I am checking several 50+ directories so have used GetFiles as some posts on stackoverflow say this is the most efficient method.

        Dim FullPath As String = (Server.MapPath("~\Docs\" & strDirectoryPath))

        If Directory.Exists(FullPath) Then
            Dim s() As String = Directory.GetFiles(FullPath)
            If s.Length = 0 Then
                Return "Empty"
            Else
                Return String.Format("{0} files/s", s.Length)
            End If
        Else
            Return "Empty" 'Directory Does Not Exist
        End If

Open in new window


Any help is appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sanjshah12

ASKER

Many thanks Pawan that works great!