MATLAB: Is there any way to list all folders ONLY in the level directly below a selected directory

directoryfilesgenpathpath

I want to generate a list of all of the subfolders within a directory. I was using genpath for this. Unfortunately, each of these subfolders also has 4 subfolders of tehir own, and I don't want them included in this list.
Is there any command that can list the folders only one level below the directory I indicate?

Best Answer

John, simply use dir():
% Get a list of all files and folders in this folder.
files = dir('C:\Users\John\Documents\MATLAB\work')
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir]
% Extract only those that are directories.
subFolders = files(dirFlags)
% Print folder names to command window.
for k = 1 : length(subFolders)
fprintf('Sub folder #%d = %s\n', k, subFolders(k).name);
end