473,491 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read dir into Dataset

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
3 3776
"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
"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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1782
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
1
10239
by: Sal | last post by:
Hello all, I am working on a project with the following characteristics: 1. Load data from a SQL server table to an xml file 2. Read the xml file into a dataset. 3. Load data from the...
0
4674
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
15
4734
by: ruca | last post by:
Hi, Can I read a .TXT File to a DataSet? How can I do that? I want to read his lines to a DropDownList. This lines are the names of employees that I export from an application that I have. I...
5
7764
by: Guadala Harry | last post by:
This has to be easy... I have a DataSet stored in the Session object. I simply need to read it later and get the following error: Cannot implicitly convert type 'object' to 'System.Data.DataSet'...
3
2295
by: Programmer | last post by:
Hi all I wan't to know if i'm able to read mail from a mail server. My mail server is a pop3 server (UNIX) and i want to be able to get the mails from an aspx or an asmx. with out using external...
1
1836
by: D. Shane Fowlkes | last post by:
How can I loop through the rows of a DataSet and send the "fields" to the Function as I've attempted to do in my code? Error is at "While dsLineItems.Read()" . I'm trying to construct a Sub which...
16
453
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
0
1252
by: Hetal | last post by:
Hi there.. I am a VB6 developer so kinda trying to figure how to work with VB.NET. I have a scenario where i have a DataSet bound to a combo box, and i would like to read a row from the DataSet...
0
2260
by: tom | last post by:
When I try to read in a csv file it gives me this error message. 'Cannot update. Database or object is read-only.' If I change the extension to txt it processes just fine. I have googled all...
0
7115
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.