下面显示的Matlab脚本列出了当前目录中的所有文件夹。如何列出符合特定通配符模式的所有文件夹,例如*pattern*
或Sample*
?
files = dir(pwd)
% 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