|
-
Nov 11th, 2001, 10:50 PM
#1
Thread Starter
Lively Member
Listing all folders in a directory
Hi,
My previous post was too confusing and broad. So I'll start here:
How do I list all the folders of a folder or directory into a listbox?
If it isn't possible to list them into a listbox what other way can I list them? I need the list to be able to have a folder selected so the user can delete it, though.
Thanks
J.KLEIN
-
Nov 11th, 2001, 10:51 PM
#2
Member
Why not just use a DirListBox? It does it automatically.
-
Nov 11th, 2001, 10:57 PM
#3
Thread Starter
Lively Member
Why?
I don't know if that will work with my program.
The program will search in a specific game directory of a user's machine, find all folders and list them.
The user will then have the option to add a new folder or delete current folders that are listed.
If this can be done with a DirListBox, then maybe you can help?
Thanks,
JKLEIN
-
Nov 11th, 2001, 11:59 PM
#4
PowerPoster
DirListBox is read-only. You can list all folders in (and above) a directory .Path, but not add folders. For that you will need to use FSO.
Set a reference in your proj to Microsoft Scripting Runtime.
The do something like this:
Dim FSO As New FileSystemObject
FSO.CreateFolder "C:\test\"
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Nov 12th, 2001, 12:00 AM
#5
PowerPoster
If you're doing this to save files or something, you might prefer to use a CommonDialog control, which has this sort of thing done for you.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Nov 12th, 2001, 12:04 AM
#6
Originally posted by rjlohan
DirListBox is read-only. You can list all folders in (and above) a directory .Path, but not add folders. For that you will need to use FSO.
Set a reference in your proj to Microsoft Scripting Runtime.
The do something like this:
Dim FSO As New FileSystemObject
FSO.CreateFolder "C:\test\"
As a quick note, FSO is not required if you want to make a directory. VB provides MkDir for that purpose:
MkDir "c:\new folder"
-
Nov 12th, 2001, 12:06 AM
#7
PowerPoster
I'll be damned. Who'dve thought?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Nov 12th, 2001, 12:11 AM
#8
Okay, here's a subroutine to fill a listbox with all the subdirectories in a particular folder:
VB Code:
Sub ListDirs(ByVal sDir As String, lbListBox As ListBox)
Dim sFileDir As String
If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
sFileDir = Dir(sDir & "*.*", vbDirectory)
Do Until sFileDir = ""
If (GetAttr(sDir & sFileDir) And vbDirectory) = vbDirectory Then
If sFileDir <> "." And sFileDir <> ".." Then
lbListBox.AddItem sFileDir
End If
End If
sFileDir = Dir
Loop
End Sub
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
|