Specifications

List Box Directory Reader
5-23
The open statement is called within a try/catch block to capture errors in an
error dialog (
errordlg), instead of returning to the command line.
function varargout = listbox1_Callback(h,eventdata,handles,varargin)
if strcmp(get(handles.figure1,'SelectionType'),'open') % If double click
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
filename = file_list{index_selected}; % Item selected in list box
if handles.is_dir(handles.sorted_index(index_selected)) % If directory
cd (filename)
load_listbox(pwd,handles) % Load list box with new directory
else
[path,name,ext,ver] = fileparts(filename);
switch ext
case '.fig'
guide (filename) % Open FIG-file with guide command
otherwise
try
open(filename) % Use open for other file types
catch
errordlg(lasterr,'File Type Error','modal')
end
end
end
end
Opening Unknown File Types
You can extend the file types that the open command recognizes to include any
file having a three-character extension. You do this by creating an M-file with
the name
openxyz, where xyz is the extension. Note that the list box callback
does not take this approach for .fig files since
openfig.m is required by the
application M-file. See
open for more information.