473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Display the contents of a folder in a listbox?

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
9 18887
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
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
"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
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

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

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

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

Similar topics

2
by: Graham J | last post by:
Hello, Apologies for the somewhat wordy and garbled subject as I couldn't think how to phrase it and this has hindered my searching for any previous answers. It could be a really simple...
1
by: Seth Delaney | last post by:
I have a form with a combobox and a list box. The combobox will list records (names of queries) that are entered in a table called tblListName. I have the combobox set to get its values from this...
4
by: Hardy Wang | last post by:
Hi I have a ListBox control in my ASP.NET page. After I binding data to this control, I would like to be able to change this display order of items in this control. Just like change layout...
1
by: NBB | last post by:
I can't figure this one out. Here's the situation, should be pretty for the pros in here. I have a ListBox that is populated with the DataTextField and DataValueField flags of the DataSet....
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
1
by: rallard | last post by:
After the following subroutine executes, my listview shows a scroll bar on the right, but it is otherwise blank. I've checked for things like locked=false, visable=true, font color same as...
2
by: tks423 | last post by:
How can I determine the values of a listbox, both unselected or selected after submitting the form: Code: <select name="sel1" size="10" multiple="multiple"> <? PHP code populates listbox ?>...
7
by: jacobevans | last post by:
i need some help opening a text file and having the contents in that file add to a list. for example a user types '/addlist C:/text.txt'. the program takes the c:/text.txt and adds the items to...
1
by: PulkitZery | last post by:
Hi, I am creating a webpage in vb.net and this webpage has frames. Now the problem I have is, in one of the frames I want to show a MS Word or PDF file. If I set the source of this frame to...
2
by: Plumebee | last post by:
Hi, I am very new to programming and have just started to use Visual Basic 2005 Express Edition. I am trying to read from a text file to draw a rectangles and lines. However to begin I'm trying to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.