How do I get only the subfolders of a folder?

How do I get only the subfolders of a folder?
The "dir" command gives a struct with all the subfolders as well as all the files and '.', '..'.

 Accepted Answer

The following code, returns a struct containing only the subfolders of a folder.
% get the folder contents
>> d = dir('foldername')
% remove all files (isdir property is 0)
>> dfolders = d([d(:).isdir])
% remove '.' and '..'
>> dfolders = dfolders(~ismember({dfolders(:).name},{'.','..'}))

More Answers (0)

Categories

Products

Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!