
November 10th, 2005, 02:42 PM
|
|
Contributing User
|
|
Join Date: Nov 2005
Location: Canto 34
Posts: 35
Time spent in forums: 9 h 41 m 47 sec
Reputation Power: 3
|
|
|
VB.Net: FileSystem Directory Tree Constructor
This is a quick snippet that will populate a string array based on a parent directory with all of it's child directories (no matter how deep they are in the file system structure).
strPath is the directory for the parent
Code:
Dim arrstrHold() As String
Dim repeater As Integer = 0
Dim dynamicCount As Integer = 0
arrstrHold = IO.Directory.GetDirectories(strPath)
dynamicCount = arrstrHold.Length
Do While (repeater < dynamicCount)
If IO.Directory.GetDirectories(arrstrHold(repeater)). Length > 0 Then
ReDim Preserve arrstrHold(UBound(arrstrHold) + IO.Directory.GetDirectories(arrstrHold(repeater)). Length)
IO.Directory.GetDirectories(arrstrHold(repeater)). CopyTo(arrstrHold, arrstrHold.IndexOf(arrstrHold, Nothing))
dynamicCount += IO.Directory.GetDirectories(arrstrHold(repeater)). Length
End If
repeater += 1
Loop
It assumes that all the child directories of the parent have atleast read access. I am attempting to find a way around this without using exceptions. Until then, you can place a try/catch around "If IO.Directory.GetDirectories(arrstrHold(repeater)). Length > 0" and it will work fine for now.
|