MATLAB: How to create an App Designer App that lists the contents of a user-chosen directory

appapp_designerbrowsedesignerdirMATLABuigetdiruitable

I would like to design an app that allows the user to browse for a folder, that displays the folder location, and that displays the folder contents to the app. I would like to use App Designer to make the app. How can I do this in App Designer?

Best Answer

Refer to the attached example App Designer file named 'ExampleDirectoryApp.mlapp'. In the attached example App, there is a 'browse' button, a label to display the selected folder location, and a uitable to display the contents of the selected folder location. When the app is run, the user clicks on the 'browse' button to trigger a callback. The callback executes the 'uigetdir' command to get the directory and then displays the directory to the label. Finally, the callback obtains the directory contents using the 'dir' command and displays the contents in the uitable.
For more information and details about the implementation, refer to the attached file and the comments in the file. Please note that, because the contents of the directory are displayed in a uitable, the contents are selectable. That is, if desired, the 'CellSelectionCallback' can be created on the uitable to execute code based on the user's selection of the folder's contents. Please also note that the app was designed to be run in MATLAB R2018a.
For more information about the relevant functions and callbacks in this example app, please refer to the following links:
NB: If you are having trouble downloading the attachment, please right-click on the file and select 'Save link as...'.