The DIR function returns an array of structures, one for each directory entry. One element of the structure is a flag named isdir .
mydir = 'c:\test'; allentries = dir(mydir); % array of all files and dirs within target diridxs = [allentries.isdir]; alldirs = allentries(diridxs); % array of all the dirs allfiles = allentries(~diridxs); % array of all the files for ctr = 1:length(allfiles) disp(allfiles(i).name)
Please note that catalog entries are included . and .. which can be confusing when you try to parse a directory tree recursively ...
source share