Make your own free website on Tripod.com

Put Drives, Directories And Files In One List Box

'Add 1 List Box, 1 Drive List Box, 1 Dir List Box, 1 File List Box and 1 Label
'to your form.

'Insert the following code to your form:

Function StripPath(T$) As String
Dim x%, ct%
StripPath$ = T$
x% = InStr(T$, "\")
Do While x%
ct% = x%
x% = InStr(ct% + 1, T$, "\")
Loop
If ct% > 0 Then StripPath$ = Mid$(T$, ct% + 1)
End Function

Sub UpdatePath()
Dim I, D, J, K As Integer
For D = 0 To List1.ListCount - 1
List1.RemoveItem "0"
Next D
If Not Right(Dir1.List(-1), 1) = "\" Then
List1.AddItem "[^] .."
End If
For I = 0 To Dir1.ListCount - 1
List1.AddItem "[\] " & StripPath(Dir1.List(I))
Next I
For J = 0 To File1.ListCount - 1
List1.AddItem "[*] " & File1.List(J)
Next J
For K = 0 To Drive1.ListCount - 1
List1.AddItem "[o] " & Drive1.List(K)
Next K
Label1.Caption = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
UpdatePath
End Sub

Private Sub Form_Load()
Drive1.Visible = False
File1.Visible = False
Dir1.Visible = False
UpdatePath
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
End Sub

Private Sub List1_DblClick()
If Right(List1.Text, 2) = ".." Then
Dir1.Path = Dir1.Path & "\.."
ElseIf Left(List1.Text, 3) = "[\]" Then
If Right(Dir1.List(-1), 1) = "\" Then
Dir1.Path = Dir1.Path & Right(List1.Text, Len(List1.Text) - 4)
Else
Dir1.Path = Dir1.Path & "\" & Right(List1.Text, Len(List1.Text) - 4)
End If
ElseIf Left(List1.Text, 3) = "[o]" Then
Drive1.Drive = Right(Left(List1.Text, 6), 2)
Else
MsgBox "File " & Chr(34) & Right(List1.Text, Len(List1.Text) - 4) & _
Chr(34) & " was chosen.", vbInformation, "File Chosen"
End If
End Sub

Go Back