I've made myself a class for enumerating folders. But I'm a bit
confused how to use it. It looks like this:
'--Class begin
Imports System.IO
Public Class ListFolders
Private _folder As String
Private _listSubFolders As Boolean
Sub New(ByVal Folder As String, ByVal ListSubDirs As Boolean)
_folder = Folder
_listSubFolders = ListSubDirs
End Sub
Public ReadOnly Property GetFolder()
Get
Return _folder
End Get
End Property
Private Sub ProcessDirectory(ByVal targetDirectory As String,
ByVal getSubFolders As Boolean)
Try
Dim fileEntries As String() =
Directory.GetFiles(targetDirectory)
Dim subdirectoryEntries As String() =
Directory.GetDirectories(targetDirectory)
Dim fileName As String, folderName As String, subdirectory
As String
If getSubFolders = True Then
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory, True)
Next subdirectory
End If
For Each folderName In subdirectoryEntries
_folder = folderName
Next folderName
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
'--Class end
My call looks like:
Dim lf As ListFolders
lf = New ListFolders("c:\", False)
...but then what? How do I make my class keep returning each folder? Or
should my class return an array...or..or?
I'm bit of a newbie to .net, so any comments on the code in general is
also more than welcomed (except for missing error handling which i
know is missing).
Thanks in advance for any help! :-)
Regards /Morten