By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Read dir into Dataset

P: n/a
Hi,

Does anyony know how to read an entire directory into a DataSet, including
all sub-directories and filenames ?

Thanx

John
Jul 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"John Devlon" <jo********@hotmail.comskrev i meddelelsen
news:qQ*****************@phobos.telenet-ops.be...
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(S earchString),
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

Jul 17 '07 #2

P: n/a
"John Devlon" <jo********@hotmail.comskrev i meddelelsen
news:qQ*****************@phobos.telenet-ops.be...
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(S earchString),
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

Jul 17 '07 #3

P: n/a

Sub Main ()
Dim DT As New System.Data.DataTable
DT.Columns.Add("path")
GetDirs("c:\", DT)
Dim DS As System.Data.DataSet = dt.DataSet
DataGrid1.DataSource = DS
DataGrid1.DataBind()
End Sub

Sub GetDirs(ByVal Root As String, ByRef DT As
System.data.DataTable)
Try
Dim row As System.data.DataRow = DT.NewRow
row("path") = Root
DT.Rows.Add(row)
Dim Dirs() As String = IO.Directory.GetDirectories(Root)
For i As Integer = 0 To Dirs.Length - 1
GetDirs(Dirs(i), DT)
Next
Catch ex As Exception

End Try
End Sub

Developers list your services
http://directory.kr3at.com

Jul 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.