"Anthony P." <pa*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hello Everyone,
I am building an application and I need to walk the file system from
the root directory on down. I need to cover every single directory on
the system and all of their sub directories. Basically, I am trying to
programatically obtain a count of how many files the system has.
Any ideas on how to walk the filesystem in VB.NET or if there is a
better way to get a file count?
Thanks!
Anthony
I'm not saying its the most efficient code, but I leeced if from somewhere
and it works
Public FileArray As New ArrayList
Private Sub Recurse(ByVal DirPath As String, ByVal IncludeSubFolders As
Boolean)
Dim objFileInfo As FileInfo
Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
Dim objSubFolder As DirectoryInfo
Try
' This bit does the getting of files in the current folder
Console.WriteLine("Processing Folder: " & objDir.FullName)
StsCurrentFile.Text = "Processing Folder: " & objDir.FullName
For Each objFileInfo In objDir.GetFiles()
Console.WriteLine("Processing File: " & objFileInfo.Name & vbTab
& objFileInfo.LastWriteTime)
FileArray.Add(objFileInfo)
Next
' This bit does the recursion for subdirs
If IncludeSubFolders Then
For Each objSubFolder In objDir.GetDirectories()
Console.WriteLine("Processing Subfolder: " & objDir.FullName)
'Console.WriteLine(Recurse(objSubFolder.FullName,
IncludeSubFolders))
Recurse(objSubFolder.FullName, IncludeSubFolders)
Next
End If
Catch Ex As Exception
MsgBox("Err - " & Err.Number & vbNewLine & vbNewLine &
Err.Description & vbNewLine & vbNewLine & Err.GetException.StackTrace &
vbNewLine & vbNewLine & Err.Source & vbNewLine & vbNewLine &
Err.GetException.Source)
End Try
End Sub