Results 1 to 8 of 8

Thread: Listing all folders in a directory

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    70

    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

  2. #2
    Why not just use a DirListBox? It does it automatically.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    70
    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

  4. #4
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    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]
    -----------------------------------------

  5. #5
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    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]
    -----------------------------------------

  6. #6
    Tygur
    Guest
    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"

  7. #7
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    I'll be damned. Who'dve thought?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  8. #8
    Tygur
    Guest
    Okay, here's a subroutine to fill a listbox with all the subdirectories in a particular folder:
    VB Code:
    1. Sub ListDirs(ByVal sDir As String, lbListBox As ListBox)
    2. Dim sFileDir As String
    3. If Right(sDir, 1) <> "\" Then sDir = sDir & "\"
    4. sFileDir = Dir(sDir & "*.*", vbDirectory)
    5. Do Until sFileDir = ""
    6.     If (GetAttr(sDir & sFileDir) And vbDirectory) = vbDirectory Then
    7.         If sFileDir <> "." And sFileDir <> ".." Then
    8.             lbListBox.AddItem sFileDir
    9.         End If
    10.     End If
    11.     sFileDir = Dir
    12. Loop
    13. 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
  •  



Click Here to Expand Forum to Full Width