📅  最后修改于: 2022-03-11 14:56:20.347000             🧑  作者: Mango
% 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