|
-
Mar 17th, 2009, 03:57 AM
#1
Thread Starter
Member
[RESOLVED] Directory Items TO Listbox Items
Any help would be greatly appreciated. I'm making an application that does some stuff involving the given subject, so this is very crucial to the completion and efficiency of my application.
What I'm in need of today is simple (well, "seems" simple). I have one listbox that I want to populate with directories file's names. I don't mean the files inside the directories, but the names of the folders inside the directory.
So, I have "c:\temp\dog", I'd click on my button or whatever and search for the directory and I choose "temp", said listbox would show "dog".
Thanks, VBForums.
UPDATE: Oh, BTW. It doesn't HAVE to be a listbox, it can be anything (IE: Textbox, Labels, Etc.).
Home of Nuova Cartella (Mass Folder Creator)
-
Mar 17th, 2009, 05:05 AM
#2
Re: Directory Items TO Listbox Items
Hey,
Have you looked at the FolderBrowserDialog Class:
http://msdn.microsoft.com/en-us/libr...serdialog.aspx
Also, you might want to look at the System.IO.Directory Class:
http://msdn.microsoft.com/en-us/libr...y_members.aspx
There are members in there for doing exactly what you want.
Hope that helps!!
Gary
Last edited by gep13; Mar 17th, 2009 at 07:49 AM.
-
Mar 17th, 2009, 05:34 AM
#3
Lively Member
Re: Directory Items TO Listbox Items
''try to use
vb Code:
Dim di As New IO.DirectoryInfo("c:\temp")
'' for adding directories
For Each d As IO.DirectoryInfo In di.GetDirectories
ListBox1.Items.Add(d.Name)
Next
'' for adding files
For Each f As IO.FileInfo In di.GetFiles
ListBox1.Items.Add(f.Name)
Next
-
Mar 17th, 2009, 05:39 AM
#4
Re: Directory Items TO Listbox Items
Something like
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each FolderName As String In IO.Directory.GetDirectories("D:\", "*")
ListBox1.Items.Add(FolderName)
Next
End Sub
-
Mar 17th, 2009, 07:29 AM
#5
Thread Starter
Member
Re: Directory Items TO Listbox Items
 Originally Posted by softkans
''try to use
vb Code:
Dim di As New IO.DirectoryInfo("c:\temp")
'' for adding directories
For Each d As IO.DirectoryInfo In di.GetDirectories
ListBox1.Items.Add(d.Name)
Next
'' for adding files
For Each f As IO.FileInfo In di.GetFiles
ListBox1.Items.Add(f.Name)
Next
You think this might do?:
Code:
Dim gen
Dim = inputbox("Directory Input:")
Dim di As New IO.DirectoryInfo(gen)
'' for adding directories
For Each d As IO.DirectoryInfo In di.GetDirectories
ListBox1.Items.Add(d.Name)
Next
'' for adding files
For Each f As IO.FileInfo In di.GetFiles
ListBox1.Items.Add(f.Name)
Next
Home of Nuova Cartella (Mass Folder Creator)
-
Mar 17th, 2009, 07:37 AM
#6
Re: Directory Items TO Listbox Items
Hey,
What are you expecting that code to do?
I don't think it will even compile.
I think what you are after is this:
Code:
Dim gen As String
gen = inputbox("Directory Input:")
Dim di As New IO.DirectoryInfo(gen)
'' for adding directories
For Each d As IO.DirectoryInfo In di.GetDirectories
ListBox1.Items.Add(d.Name)
Next
'' for adding files
For Each f As IO.FileInfo In di.GetFiles
ListBox1.Items.Add(f.Name)
Next
Having said that though, why are you using an InputBox rather than a FolderBrowserDialog? Using an InputBox is prone to spelling mistakes etc.
Also, you original post didn't mention looping through the files in the folder, just the directories. What exactly is it you are wanting?
Hope that helps!!
Gary
Last edited by gep13; Mar 17th, 2009 at 07:49 AM.
-
Mar 17th, 2009, 08:55 AM
#7
Thread Starter
Member
Re: Directory Items TO Listbox Items
How could I substitute a inputbox with a folderbrowsedialog?
I'm trying to get all folder names and get them inside a listbox. Basically, every "dir" name becomes a line in the listbox.
UPDATE: I tried your code, it worked perfectly. Thread resolved. Although, I'm still interested in finding out the question to my answer above. :P
Last edited by Undocked Windy; Mar 17th, 2009 at 08:59 AM.
Home of Nuova Cartella (Mass Folder Creator)
-
Mar 17th, 2009, 08:59 AM
#8
Re: Directory Items TO Listbox Items
All folder names on the entire drive?
That wasn't the original question. Are you changing it now?
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
|