populate a listbox with selected folder doc file names - App designer

How can I populate a listbox with all doc files in a selected folder using a button in App designer?
function selectDocButtonPushed(app, event)
app.selectedPath = uigetdir();
docFileInfo = dir('*.doc')
app.docListBox.Items = docFileInfo.name
end

 Accepted Answer

Give this a shot,
docFileInfo = dir(fullfile(app.selectedPath, '*.doc'));
app.docListBox.Items = {docFileInfo.name}';

4 Comments

Thanks a lot . BTW how can I disp/store the selected folder+file in a variable?
ff = fullfile({docFileInfo.folder}, {docFileInfo.name})';
Thank a lot. I meant how can I store the one file which is marked/selected in the listbox?
Here's what you need to know about the listbox.
1) app.ListBox.Items stores what you seein the list.
2) app.ListBox.ItemsData is used to store optiona info about each item in the list. This is what is returned when you fetch the currently selected item.
3) app.ListBox.Value returns the currently selected ItemsData.
So, what I recommend is to store the file names in Items and the full paths in ItemsData. Then, to get the full path of the selected item, you just need to access the Value property.

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 10 Aug 2020

Edited:

on 11 Aug 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!