|
-
Jan 15th, 2009, 02:08 PM
#1
Thread Starter
Lively Member
[2008] listbox help
Hey,
I'm having some trouble with list boxes at the moment. I need a list box to display the names of directories that are in certain a folder. How can I do this? Thanks in advance!
-
Jan 15th, 2009, 02:17 PM
#2
Re: [2008] listbox help
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each folder As String In IO.Directory.GetDirectories("c:\red_bull_NRG")
ListBox1.Items.Add(IO.Path.GetFileName(folder))
Next
End Sub
-
Jan 15th, 2009, 02:18 PM
#3
Re: [2008] listbox help
First issue is related to directories so first search in forums how you can find directories in particular folder.
-
Jan 15th, 2009, 02:19 PM
#4
Re: [2008] listbox help
You can use the IO.Directory.GetDirectories() method for that, like this:
vb Code:
For Each Directory As String In IO.Directory.GetDirectories("C:\", "*", IO.SearchOption.TopDirectoryOnly)
MyListBox.Items.Add(Directory)
Next
As you can see from the arguments I have passed in, I am just setting it to search the root of the C drive for folders and I have told it to not search subdirectories too.
There is an equivalent method for files (unsurprisingly called GetFiles) too. I think both are available in My.Computer.FileSystem as well as the IO namespace
EDIT: Damn Hack beat me to it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|