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

Display the contents of a folder in a listbox?

P: n/a
I have developed several databases in Access. I know VBA. I am making the
jump to VB and am currently using Visual basic 2005 Express.

Can anyone give me a snippet that will show me how to list the contents of a
directory in a listbox.

If you could also point me toward a good beginners VB 2005 book or website I
would appreciate it.

Regards,

Paul
Jan 16 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
hi,
i'm using VS2003 as VS2005 is still in beta stage. but you can use
this code in both version.

first you need to import this name space :

Imports System.IO

than you can paste this code in a procedure or in Load event of the
form :

Dim filInfo As FileInfo
For Each fil As String In Directory.GetFiles("d:\temp")
filInfo = New FileInfo(fil)

ListBox1.Items.Add(filInfo.Name)
Next

Dim DirInfo As DirectoryInfo
For Each dir As String In Directory.GetDirectories("d:\temp")
DirInfo = New DirectoryInfo(dir)
ListBox1.Items.Add("[DIR] " & DirInfo.Name)
Next

this will fetch info from the Directory and fill the ListBox.

and the site for the ebook. you can try this one:

http://www.ingenieriauai.com.ar/eBooks/
PW: 01007011

i hope this will help you.

Jan 16 '06 #2

P: n/a
Hi,

Another book link

http://www.vb-tips.com/default.aspx?...5-e16db864a414

Ken
-------------
"Paul H" <no****@nospam.com> wrote in message
news:N9*******************@newsfe4-win.ntli.net...
I have developed several databases in Access. I know VBA. I am making the
jump to VB and am currently using Visual basic 2005 Express.

Can anyone give me a snippet that will show me how to list the contents of
a directory in a listbox.

If you could also point me toward a good beginners VB 2005 book or website
I would appreciate it.

Regards,

Paul

Jan 16 '06 #3

P: n/a
"Paul H" <no****@nospam.com> schrieb:
I have developed several databases in Access. I know VBA. I am making the
jump to VB and am currently using Visual basic 2005 Express.

Can anyone give me a snippet that will show me how to list the contents of
a directory in a listbox.


\\\
Imports System.IO
....
For Each FileName As String In Directory.GetFiles(...)
Me.ListBox1.Items.Add(Path.GetFileName(FileName))
Next FileName
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 16 '06 #4

P: n/a
Jon
VS 2005 has been out of beta and available to the public for a couple months
now.
"Lucky" <tu************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
hi,
i'm using VS2003 as VS2005 is still in beta stage. but you can use
this code in both version.

Jan 16 '06 #5

P: n/a

"Paul H" <no****@nospam.com> wrote in message
news:N9*******************@newsfe4-win.ntli.net...
I have developed several databases in Access. I know VBA. I am making the
jump to VB and am currently using Visual basic 2005 Express.

Can anyone give me a snippet that will show me how to list the contents of
a directory in a listbox.

If you could also point me toward a good beginners VB 2005 book or website
I would appreciate it.


I'm still playing with this but:

Dim S As String, I As Integer, L As ListViewItem, J As Long, T As Date
For I = 0 To CheckedListBox1.Items.Count - 1
S = CheckedListBox1.Items(I)
dlgOpenFile.InitialDirectory = S
For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
S, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
ListView2.Items.Add(foundFile)
L = ListView2.Items(ListView2.Items.Count - 1)
L.Checked = True
Next

I'm using a ListView but a Listbox works too.

Feb 27 '06 #6

P: n/a
Ok doing something like this to fill a listview. The first time the following
line of code runs it takes like 15-20 seconds. If I open the form again it
takes about 5 seconds. If I stop the app and wait 15 minutes or so and start
the app in debug again the delay is there, but if start the app in debug
immediatly after stopping a debug session there is no delay.
Dim files() As System.IO.FileInfo = dirInfo.GetFiles("*.nc")

"Homer J Simpson" wrote:

"Paul H" <no****@nospam.com> wrote in message
news:N9*******************@newsfe4-win.ntli.net...
I have developed several databases in Access. I know VBA. I am making the
jump to VB and am currently using Visual basic 2005 Express.

Can anyone give me a snippet that will show me how to list the contents of
a directory in a listbox.

If you could also point me toward a good beginners VB 2005 book or website
I would appreciate it.


I'm still playing with this but:

Dim S As String, I As Integer, L As ListViewItem, J As Long, T As Date
For I = 0 To CheckedListBox1.Items.Count - 1
S = CheckedListBox1.Items(I)
dlgOpenFile.InitialDirectory = S
For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
S, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
ListView2.Items.Add(foundFile)
L = ListView2.Items(ListView2.Items.Count - 1)
L.Checked = True
Next

I'm using a ListView but a Listbox works too.

Mar 27 '06 #7

P: n/a

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
Ok doing something like this to fill a listview. The first time the
following
line of code runs it takes like 15-20 seconds. If I open the form again it
takes about 5 seconds. If I stop the app and wait 15 minutes or so and
start
the app in debug again the delay is there, but if start the app in debug
immediatly after stopping a debug session there is no delay.
Dim files() As System.IO.FileInfo = dirInfo.GetFiles("*.nc")


It seems that Windows does some sort of storing/buffering of directories, so
sometimes the info may come from a buffer, sometimes it re-reads it.

I notice that the CD/DVD drive is particularly cranky this way.

Mar 27 '06 #8

P: n/a
Dear Lucky:

This is IGFET909.

You mentioned an ebook from http://www.ingenieriauai.com/ar/eBooks/ for
access by Paul H.

Would you happen to know whether there is an ebook for Microsoft Visual
Basic 2005 Express?

Thanks.
*******
D.R.Steele
"Lucky" wrote:
hi,
i'm using VS2003 as VS2005 is still in beta stage. but you can use
this code in both version.

first you need to import this name space :

Imports System.IO

than you can paste this code in a procedure or in Load event of the
form :

Dim filInfo As FileInfo
For Each fil As String In Directory.GetFiles("d:\temp")
filInfo = New FileInfo(fil)

ListBox1.Items.Add(filInfo.Name)
Next

Dim DirInfo As DirectoryInfo
For Each dir As String In Directory.GetDirectories("d:\temp")
DirInfo = New DirectoryInfo(dir)
ListBox1.Items.Add("[DIR] " & DirInfo.Name)
Next

this will fetch info from the Directory and fill the ListBox.

and the site for the ebook. you can try this one:

http://www.ingenieriauai.com.ar/eBooks/
PW: 01007011

i hope this will help you.

Mar 27 '06 #9

P: n/a

"IGFET909" <IG******@discussions.microsoft.com> wrote in message
news:03**********************************@microsof t.com...
You mentioned an ebook from http://www.ingenieriauai.com/ar/eBooks/ for
access by Paul H.

Would you happen to know whether there is an ebook for Microsoft Visual
Basic 2005 Express?


You get one free when you register Visual Basic 2005 Express

Mar 27 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.