MATLAB: Automatically take folder directories of one level up

directoryfolder listing

I have 3 folders of images. Now I want to enter into one folder and select that directory. Then I want matlab to go back to one level up and automatically select other two folder's directory. Is there any easirer way to do that?
Thanks in advance

Best Answer

Try this:
[parentFolder, thisFolder] = fileparts(ImageFolder)
fileListing = dir(parentFolder) % List of everything: folders and files:
% Get a list of only the folders
areAFolder = [fileListing.isdir];
% Extract only those items that are folders, not files;
folderListing = fileListing(areAFolder)
% Just for fun, list all the folders that we found:
fprintf('Found these %d child folders of "%s" :\n', length(folderListing), parentFolder)
for k = 1 : length(folderListing)
thisFolder = fullfile(folderListing(k).folder, folderListing(k).name);
fprintf('%s\n', thisFolder);
end
Do not use addpath() ! !