Solved

How do you add a dir toa list box? (urgent)

Posted on 2000-03-13
5
148 Views
Last Modified: 2010-05-02
How do you add like all the names of the directories in a directory to a combo box? Then add the files of a directory to a list box? Please give a vivid discription I am slow :-) and lazy. :-( YaY thanx.
0
Comment
Question by:Shroom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 28

Expert Comment

by:Ark
ID: 2614892
0
 

Expert Comment

by:AshokKumar
ID: 2614907
Comeon friend, y u need this. U have a built in control shipped with VB namely File list box and directory list box. ANyway, if u need this, just try this. Place a directory list box and a sile list box in the form. Hide both controls. Give the Initial path for directory list box as the directory u wish and the file list box path property as directory list box's path. Then all the sub directories will be loaded in the directory list box and files in the corresponding folder into file list box. Nowe just add the items in the combo box and list box respectively. Simple. Right? Pls. get baqck to me.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2614913
Why not just use a DirListBox and a FileListBox??

Anyhow, here's the code to do it:

    Dim dirName As String
    Dim lBuf As String
    Dim lPath As String
   
    lPath = "C:\"
   
    Combo1.Clear
    List1.Clear
    dirName = Dir(lPath, vbDirectory)
    Do While Not dirName = ""
        lBuf = IIf(Right$(lPath, 1) = "\", lPath, lPath & "\") & dirName
        If GetAttr(lBuf) = vbDirectory Then
            Combo1.AddItem dirName
        Else
            List1.AddItem dirName
        End If
        dirName = Dir
    Loop


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2614926
by the way, the code I gave you does not require a DirListBox or a FileListBox...

Also to change the directory you want to load, change the "lPath" variable...


Cheers!®©
0
 
LVL 28

Expert Comment

by:Ark
ID: 2615079
Hi
If you too lazy, get all the code
You need form with List1 listbox on it

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Const LB_DIR = &H18D
Const LB_RESETCONTENT = &H184

Const DDL_READWRITE = &H0
Const DDL_READONLY = &H1
Const DDL_HIDDEN = &H2
Const DDL_SYSTEM = &H4
Const DDL_DIRECTORY = &H10
Const DDL_ARCHIVE = &H20
Const DDL_DRIVES = &H4000
Const DDL_EXCLUSIVE = &H8000
Const DDL_POSTMSGS = &H2000

Dim DirName As String

Private Sub Form_Load()
   Dim StartDir  As String
   DirName = "c:\"
   Call SendMessage(List1.hwnd, LB_RESETCONTENT, 0, ByVal 0)
   Call SendMessage(List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal DirName & "*.*")
   Call SendMessage(List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal DirName & "*.*")
   Me.Caption = DirName
End Sub

Private Sub List1_DblClick()
  Dim sName As String, lRet As Long
  sName = List1.List(List1.ListIndex)
  If Left$(sName, 1) = "[" Then
     sName = Mid$(sName, 2, Len(sName) - 2)
     If sName = ".." Then
        DirName = GetParentDir(DirName)
     Else
        DirName = DirName & sName & "\"
     End If
     Me.Caption = DirName
     Call SendMessage(List1.hwnd, LB_RESETCONTENT, 0, ByVal 0)
     Call SendMessage(List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal DirName & "*.*")
     Call SendMessage(List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal DirName & "*.*")
End If
End Sub

Private Function GetParentDir(sDir As String) As String
  For i = Len(sDir) - 1 To 1 Step -1
      If Mid$(sDir, i, 1) = "\" Then
         GetParentDir = Left$(sDir, i)
         Exit Function
      End If
  Next i
End Function

Run programm. First time listbox show you content of "c:\". Double click at any folder - you receive folders and files in it. You can go to another folder or return back clicing [..]

Cheers
PS You can add flags that you need to show system, hidden etc files
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question