Home All Groups Group Topic Archive Search About

Cointains: ??? files, ??? folders

Author
16 Oct 2006 3:10 PM
Military Smurf
Okay, so I have some code that can do a recursive search to get the raw
number of files and folders.  No big. 

As a user, I can right click on any parent folder, get the properites, and
then on the general tab, the number of child files and folders are retrieved
after a few seconds.  Is there any property or anything at all in VB.NET that
allows you to access THIS specific information?  I'm just looking for an
alternate way to get all the child folders of a parent folder near the root
of the drive.

Author
17 Oct 2006 2:01 PM
Chris Dunaway
Military Smurf wrote:
> Okay, so I have some code that can do a recursive search to get the raw
> number of files and folders.  No big.
>
> As a user, I can right click on any parent folder, get the properites, and
> then on the general tab, the number of child files and folders are retrieved
> after a few seconds.  Is there any property or anything at all in VB.NET that
> allows you to access THIS specific information?  I'm just looking for an
> alternate way to get all the child folders of a parent folder near the root
> of the drive.

You should be able to pass in any "root" folder and get the number of
child folders and files underneath it.

Something like this:

Public Sub CountFilesAndFolders(ByVal root As String, ByRef filecount
As Integer, ByRef foldercount As Integer)
    filecount = Directory.GetFiles(root, "*.*",
SearchOption.AllDirectories).Length
    foldercount = Directory.GetDirectories(root, "*.*",
SearchOption.AllDirectories).Length
End Sub

Call it like this:

Private Sub Button1_Click(....) Handles Button1.Click
    Dim iFileCount As Integer = 0
    Dim iFolderCount As Integer = 0

    CountFilesAndFolders("C:\Root Folder", iFileCount, iFolderCount)

    MsgBox("Files: " & iFileCount & ", Folders: " & iFolderCount)
End Sub

HTH