MATLAB: Grabbing all files in a folder

filesfolder

Is there anyway in matlab to grab all the files in a folder that the user select? Kind of like the uigetfile() command but that only grab the file selected. I want a way where user can select the folder and matlab will grab all the files inside of that folder. Even better if matlab can grab particular files base on the name of those files.

Best Answer

Take a look at uigetdir and dir. For example, if you want to pick out all the JPG files in a folder that the user selects:
d = uigetdir(pwd, 'Select a folder');
files = dir(fullfile(d, '*.jpg'));
% Display the names
files.name