Cointains: ??? files, ??? folders

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Military said:
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
 
Back
Top