John Devlon said:
Hi,
Does anyony know how to read an entire directory into a DataSet, including
all sub-directories and filenames ?
Thanx
John
Hi John
Here is a complete routine i used to read complete drives...
Set the 'Drv' parameter to the wanted drive/folder. i.e. GetDir("c:\")
I use it to be put into a Listbox, but you can easily change the code to put
it into a dataset instead
Hope it helps you...
/Finn
+++++++++++++++++++++++++++++++++++++
Private Sub GetDir(ByVal Drv As String)
' Create a new DirectoryInfo object.
Dim dir As New System.IO.DirectoryInfo(Drv)
If Not dir.Exists Then
Throw New System.IO.DirectoryNotFoundException("The directory
does not exist.")
End If
' Call the GetFileSystemInfos method.
Dim infos As System.IO.FileSystemInfo() =
dir.GetFileSystemInfos("*.*")
ListDirectoriesAndFiles(infos, "*.*")
TextBox2.Text = files
End Sub
Private Sub ListDirectoriesAndFiles(ByVal FSInfo() As
System.IO.FileSystemInfo, ByVal SearchString As String)
' Check the parameters.
If FSInfo Is Nothing Then
Throw New ArgumentNullException("FSInfo")
End If
If SearchString Is Nothing OrElse SearchString.Length = 0 Then
Throw New ArgumentNullException("SearchString")
End If
' Iterate through each item.
Dim i As System.IO.FileSystemInfo
For Each i In FSInfo
' Check to see if this is a DirectoryInfo object.
If TypeOf i Is System.IO.DirectoryInfo Then
' Cast the object to a DirectoryInfo object.
Dim dInfo As System.IO.DirectoryInfo = CType(i,
System.IO.DirectoryInfo)
' Iterate through all sub-directories.
ListDirectoriesAndFiles(dInfo.GetFileSystemInfos(SearchString),
SearchString)
' Check to see if this is a FileInfo object.
ElseIf TypeOf i Is System.IO.FileInfo Then
Then LB1.Items.Add(i.FullName.ToString)
End If
Next i
End Sub