Lesson XI.             FileListBox, DirectoryListBox, and DriveListBox

 

Objectives

ü       To use FileListBox, DirectoryListBox, and DriveListBox

ü       To understand how these 3 controls interact in a simple application

 

 

 


A FileListBox is a list of files in a specified directory.  A DirListBox displays the directory structure of a specified drive.  DriveListBoxes lists the drive structure of the user’s computer.

 

These three controls are initially independent of each other in the Form.  Thus, it is your job to tie them up together.  What you can probably do is to update the contents the FileListBox whenever the user selects a new folder in the DirListBox.  You can also update the directory structure of this DirListBox whenever the user selects a new drive in the DriveListBox.  The primary event of these controls is Change() — when the user selects a new item in these ListBoxes.

 

The following are the properties of a FileListBox:

 

Property

Description

Archive

Boolean.  Specifies whether or not archive attributes are displayed.  Default is True.

Hidden

Boolean.  Specifies whether or not hidden attributes are displayed.  Default is False.

MultiSelect

Integer.  Specifies whether or not the user can make multiple selections

Path

String. Specifies the current path.

Pattern

String. Specifies the files displayed in the FileListBox

ReadOnly

Boolean. Specifies whether or not read-only attributes are displayed.  Default is True.

System

Boolean. Specifies whether or not system attributes are displayed.  Default is True.

 

The most important method of a DriveListBox is Drive.  The drive method returns the current drive (in the form C: or D:) of the DriveListBox.  Using DirectoryListBox, the Path method gives you the path to the current folder or directory (e.g. C:\myfiles\computer). 


 

 


The application below is a simple file system browser.  Using FileListBox, DirectoryListBox, and DriveListBox, you can view your system’s file structure, from its drives to its directories and files.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Private Sub dirDirectory_Change()

    filFiles.Path = dirDirectory.Path

End Sub

 

Private Sub drvDrives_Change()

    dirDirectory.Path = drvDrives.Drive

End Sub

 

Private Sub txtPattern_KeyPress(KeyAscii As Integer)

    If KeyAscii = 13 Then

        filFiles.Pattern = txtPattern.Text

    End If

End Sub

 

 

Save your work as Lesson11.vbp.

 

 

 

 

 


Modify the application you have created in the Lesson in Action section.  In a Label, display the number of files found with the specified pattern in a specified location.  When the user selects a file in the FileListBox, the file name complete with its path (drive and directory) appears in another Label.