Creating Graphical User Interfaces |
 |
List Box Directory Reader
This example uses a list box to display the files in a directory. When the user double clicks on a list item, one of the following happens:
- If the item is a file, the GUI opens the file appropriately for the file type.
- If the item is a directory, the GUI reads the contents of that directory into the list box.
- If the item is a single dot (.), the GUI updates the display of the current directory.
- If the item is a double dot (..), the GUI changes to the directory up one level and populates the list box with the contents of that directory.
The following picture illustrates the GUI.

View the Layout and Application M-File
Use these links to display the FIG-file in the Layout Editor and the application M-file in the MATLAB Editor. This enables you to see the values of all component properties and to explore how the components are assembled to create the GUI. You can also see the complete code listing.
Note
The following link adds a directory to the end of your MATLAB path.
|
Click here to display the layout in GUIDE.
Click here to display the application M-file in the editor.
Implementing the GUI
The following sections describe the implementation.
- Specifying the Directory to List - shows how to pass a directory path as input argument when the GUI is launched.
- Loading the List Box - describes the subfunction that loads the contents of the directory into the list box. This subfunction also saves information about the contents of a directory in the
handles
structure.
- The List Box Callback - explains how the list box is programmed to respond to user double clicks on items in the list box.
| Protecting the GUI with a Close Request Function | | Specifying the Directory to List |  |