Assuming "image_dir" is the name of the directory, the following code shows how to determine which elements are directories and which are files, and how their names are. Once you have achieved this, creating a list of directories only or just files is easy.
dirnames = dir(image_dir);
for(i = 1:length(dirnames))
if(dirnames(i).isdir == true)
% It a subdirectory
% The name of the subdirectory can be accessed as dirnames(i).name
% Note that both '.' and '..' are subdirectories of any directory and
% should be ignored
else
% It a filename
% The filename is dirnames(i).name
end
end
source
share