List the names of folders in a drive ??? or How to find folder names in a drive?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kinnu
    New Member
    • Nov 2006
    • 30

    List the names of folders in a drive ??? or How to find folder names in a drive?

    Hi

    How to list the names of all the folders in a drive ????

    OR

    I have taken a Dir (directory list box) and text box. And using the timer, the selection of the the directories in the (directory list box) in a drive (Ex: E:\) moves top directory to last directory (using the List index property) automatically. So, when the selection selects a directory the path of the selected directory should be displayed in the text box. And when it moves down to the next directory it should display the next directory path in the text box.

    I hope am clear with the above info.

    Thanks in advance.
  • pureenhanoi
    New Member
    • Mar 2007
    • 175

    #2
    Originally posted by kinnu
    Hi

    How to list the names of all the folders in a drive ????

    OR

    I have taken a Dir (directory list box) and text box. And using the timer, the selection of the the directories in the (directory list box) in a drive (Ex: E:\) moves top directory to last directory (using the List index property) automatically. So, when the selection selects a directory the path of the selected directory should be displayed in the text box. And when it moves down to the next directory it should display the next directory path in the text box.

    I hope am clear with the above info.

    Thanks in advance.
    To get the current selected path from DirListBox, you can use the .List property
    [CODE=vb]
    Private Sub Dir1_Change()
    Text1.Text = Dir1.List(Dir1. ListIndex)
    End Sub
    [/CODE]
    To show all sub-folder in the current path, you can use Dir$() function of VB
    [CODE=vb]
    Private Sub Form_Load()
    Dim fileName As String
    Dim path As String
    Dim attrib As VbFileAttribute
    attrib = vbDirectory
    path = "C:\"
    fileName = Dir$(path,attri b)
    While Len(filename)
    List1.AddItem fileName
    fileName = Dir$
    Wend
    End Sub
    [/CODE]
    Here List1 is a ListBox, used to display all folder from "C:\"
    Change path= "C:\" to any folder that you want

    Comment

    • kinnu
      New Member
      • Nov 2006
      • 30

      #3
      Thank you so much. Both methods are helpful and wonderfulllllll l.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Thanks pureenhanoi.

        kinnu, just keep in mind that while the built-in Dir() function is certainly very quick and simple to use, the FileSystemObjec t model provides much more functionality. It's well worth learning about - look it up in the doco when you have some time.

        In the meantime though, good ol' Dir() will do the job.

        Comment

        Working...