function    [dirnames] = listdirs( pardir)

%% Retreive list of directory names within a requested directory
%
% EXAMPLE:  dirnames = listdirs( 'C:\');
%
% INPUT:    character array with location of parent directory
%
% OUTPUT:   cell array with names of directories in the parent directory
%
%                                                     Surya Gayet, 27-02-18
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% list all objects in parrent directory
f           =      dir( pardir');

% flag directories
dirFlags    =      [ f.isdir ];

% select only directory type objects
subdirs     =       f( dirFlags);

% store directory type objects in cell array
dirnames    =       {subdirs.name};

% index directory type objects '.' and '..'
remdirs     =       cellfun(@(x) ~ismember(x, {'.','..'}), dirnames, 'UniformOutput', 0);

% keep only actual directories (i.e., remove '.' and '..')
dirnames    =   dirnames( cell2mat( remdirs));


