From: Keyur Patel on
How would I make my code, so that the wav files from the current directory load onto the listbox for the gui?
From: Walter Roberson on
Keyur Patel wrote:
> How would I make my code, so that the wav files from the current
> directory load onto the listbox for the gui?

Use dir() to get the file information. Extract the name information from the
structure array returned by dir(). Build either a character array or cell
array of strings from those names, and use that character array or cell array
as the value of the String property of the listbox .
From: ImageAnalyst on
On Aug 13, 3:04 pm, "Keyur Patel" <patel_...(a)yahoo.com> wrote:
> How would I make my code, so that the wav files from the current directory load onto the listbox for the gui?

Here's some code. The adaptation to list only wav files is
straightforward.
Put a call to this function in your callback of your "Specify
Folder..." button or menu item, or in your startup code..
IMPORTANT: you may need to join any lines split into two by the
newsreader.

%=====================================================================
% --- Load up the listbox with image files in folder
handles.handles.ImageFolder
function handles=LoadImageList(handles)
ListOfImageNames = {};
folder = handles.ImageFolder;
if ~isempty(handles.ImageFolder)
if exist(folder,'dir') == false
msgboxw(['Folder ' folder ' does not exist.']);
return;
end
else
msgboxw('No folder specified as input for function LoadImageList.');
return;
end
% If it gets to here, the folder is good.
ImageFiles = dir([handles.ImageFolder '/*.*']);
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder, name, extension, version] = fileparts(baseFileName);
extension = upper(extension);
switch lower(extension)
case {'.png', '.bmp', '.jpg', '.tif', '.avi'}
% Allow only PNG, TIF, JPG, or BMP images
ListOfImageNames = [ListOfImageNames baseFileName];
otherwise
end
end
set(handles.lstImageList,'string',ListOfImageNames);
return