Folder Count method

Posted by rajivkumarnandvani on February 5, 2009

Dim fs ‘ variable declared outside a procedure (this is a global variable)
‘ this is hold a reference to the file system object
‘ create an instance
Set fs = CreateObject(“scripting.filesystemobject”)
‘ count files in windows directory
MsgBox CountFiles (“C:\Program Files\ESL India Ltd\BillingSaaClient\SAA\output”)
‘ takes a string argument containing the name of the directory

‘ returns an integer contiang the nubmer of files in that direcrectory

‘ and all sub directories

Function CountFiles (ByVal StrFolder)
Dim ParentFld
Dim SubFld
Dim IntCount
‘ note the use of the fs global variable

Set ParentFld = fs.GetFolder (StrFolder)
‘ count the number of files in the current directory

IntCount = ParentFld.subfolders.Count

For Each SubFld In ParentFld.SubFolders

‘ count all files in each subfolder – recursion point

IntCount = IntCount + CountFiles(SubFld.Path)


‘ return counted files

CountFiles = IntCount

End Function


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: